Regular Expressions find/replace needed

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
mcpilot1Asked:
Who is Participating?
 
Dan CraciunConnect With a Mentor IT ConsultantCommented:
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
 
Dan CraciunIT ConsultantCommented:
$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
 
mcpilot1Author Commented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Dan CraciunIT ConsultantCommented:
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
 
mcpilot1Author Commented:
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
 
mcpilot1Author Commented:
here is the error message when I try to run this in Dreamweaver:

Error png
0
 
Dan CraciunIT ConsultantCommented:
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
 
mcpilot1Author Commented:
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
 
mcpilot1Author Commented:
Dan was relentless in his assistance and got me a solution in the end. Thank you Dan!
0
 
Dan CraciunIT ConsultantCommented:
You're welcome.

Glad I could help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.