Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Regular Expressions find/replace needed

Posted on 2015-02-13
10
Medium Priority
?
165 Views
Last Modified: 2015-02-20
I am trying to avoid a huge manual find replace task by using regular expressions. Hopefully, due to the layout, I can pull this off. Here is what I have:

Old code

<span class="dropt" title="">[i]define this word[/i]<span style="width:300px">[i]here is the definition that will be shown in a pop up</span></span>[/i]

Open in new window


New code

<a href="#" title="<span class='red'>[i]here is the definition that will be shown in a pop up[/i]<a href='#'></a></span>">[i]define this word[/i]</a>

Open in new window


Obviously because there is a jockeying around of the position of the text that remains, cant be done with a basic search replace. There are about 100 or so instances of this with varying definitions in the document.

Thank you
0
Comment
Question by:mcpilot1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40607891
$regex = [regex] '(?m)^<span.*?\[i\](.*?)\[/i\].*?\[i\](.*?)</span></span>\[/i\]$'
$result = $regex.Replace($subject, '<a href="#" title="<span class=''red''>[i]$2[/i]<a href=''#''></a></span>">[i]$1[/i]</a>')

Open in new window

HTH,
Dan
0
 

Author Comment

by:mcpilot1
ID: 40607942
Dan, sorry for the confusion - I only added the to highlight the actual text in the code but there is no italic or emphasis. This is an examlpe of the actual code:

<span class="dropt" title="">September 11th Victim Compensation Fund
<span style="width:300px;"><b>September 11th Victim Compensation Fund: </b> A program administered by the U.S. Department of Justice that provides compensation for economic and non-economic loss to 

individuals or relatives of deceased individuals who were killed, physically injured, or made physically ill as a result of the terrorist-related aircraft crashes of September 11, 2001.</span>
</span>

Open in new window


does that change the regex formula?

Thanks,

Pat
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40608300
A bit. Try this:
$regex = [regex] '(?sm)^<span class="dropt" title="">(.*?)<span style="width:300px;">(.*?)</span>.*?</span>$'
$result = $regex.Replace($subject, '<a href="#" title="<span class=''red''>$2<a href=''#''></a></span>">$1</a>')

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:mcpilot1
ID: 40614229
I am getting a "regular expression syntax error". I am attaching the HTML file that I am workign with. Can you have a look?
handbook-working.html
0
 

Author Comment

by:mcpilot1
ID: 40618642
here is the error message when I try to run this in Dreamweaver:

Error png
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40619786
For some reason, I was sure you're trying to do the find/replace in Powershell, so I gave you Powershell code.

I don't have Dreamweaver, but I'll try and send you the instructions for Notepad++ (it's a free and very powerful text editor).
0
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 40619906
Here is the expression that seems to work in Notepad++:
Find what: <span class="dropt" title="">(.*?)<span style="width:300px;">(.*?)</span>.*?</span>
Replace with: <a href="#" title="<span class='red'>$2<a href='#'></a></span>">$1</a>

Open in new window

Notepad   s
0
 

Author Comment

by:mcpilot1
ID: 40621069
YES! It worked. I had to get v 6.x of the Notepad++ with the "matches newline" but once I did that, it worked. Thank you for your persistence. I really appreciate it.

Pat
0
 

Author Closing Comment

by:mcpilot1
ID: 40621071
Dan was relentless in his assistance and got me a solution in the end. Thank you Dan!
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40621182
You're welcome.

Glad I could help!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question