sharingsunshine
asked on
Extra Spacing In Pattern Matching
This is a follow on from this question
https://www.experts-exchange.com/questions/28370416/Pattern-Matching-LF-in-Dreamwever-CS5.html
This is my regex
This is the replacement I am using
Here is the sample data I am using.
Now here are the results I am getting
Putting the space in the replacement between $3 and $5, I get good results on #2 but #1 has two spaces between Auto and Lease and there is a problem in #3 with the word Ca r being represented with a space between the a and the r.
The problem seems to be the LF represented above as [LF] sometimes has a space between it and the preceding text. So how can I account for this in the regex?
Thanks,
Randal
https://www.experts-exchange.com/questions/28370416/Pattern-Matching-LF-in-Dreamwever-CS5.html
This is my regex
<b>([\s|\r\n]+)?<a href="(.+)?.html">(.+)?([\s|\r\n]+)?(.+)</a></b>
This is the replacement I am using
<a href="$2.html">$3 $5</a>
Here is the sample data I am using.
1. <p><b> <a href="http://www.thefrugallife.com/auto_lease.html">Getting Out of an Auto [LF]
Lease</a></b></p>
2. <b><a href="http://www.thefrugallife.com/ants1.html">Click[LF]
here!</a></b>
3. <p><b>
<a href="http://www.thefrugallife.com/new_car.html">New Car vs. Used Car</a></b> [LF]
</p>
Now here are the results I am getting
1. <p><a href="http://www.thefrugallife.com/auto_lease.html">Getting Out of an Auto Lease</a></p>
2. <a href="http://www.thefrugallife.com/ants1.html">Click here!</a>
3. <p><a href="http://www.thefrugallife.com/new_car.html">New Car vs. Used Ca r</a>
</p>
Putting the space in the replacement between $3 and $5, I get good results on #2 but #1 has two spaces between Auto and Lease and there is a problem in #3 with the word Ca r being represented with a space between the a and the r.
The problem seems to be the LF represented above as [LF] sometimes has a space between it and the preceding text. So how can I account for this in the regex?
Thanks,
Randal
ASKER
that will only take care of the 3rd example of data I am using. 1 & 2 are being passed over.
For the line breaks you can use:
regex: .html">(.*?)[\r\n]+\s*?(\w+[\w\s]*)</a>
repl: .html">$1$2</a>
Weird. In RegexBuddy, the result of the replacements are:
<a href="http://www.thefrugallife.com/auto_lease.html">Getting Out of an Auto [LF]
Lease</a>
<a href="http://www.thefrugallife.com/ants1.html">Click[LF]
here!</a>
<a href="http://www.thefrugallife.com/new_car.html">New Car vs. Used Car</a>
ASKER
I have RegexBuddy too and it won't highlight the 1st and 2nd examples. Consequently, when I do the replace it only removes the <b> tags from the 3rd one.
Are you using Javascript as the regex engine?
Are you using Javascript as the regex engine?
ASKER
then there must be something different about my test data from yours. So how do we find the differences?
RegexBuddy is just a testing tool. Instead of figuring out what's different between my setup and yours (I'm on a PC, you're on a Mac, and the line breaks are different - /r/n vs /n) let's focus on the end result.
Where do you want to use that regex? In Dreamweaver on multiple files?
On a web page?
Where do you want to use that regex? In Dreamweaver on multiple files?
On a web page?
ASKER
in dreamwever CS5 and on on all the files in the site. If this matters, my RegexBuddy is on Windows 7 too. I have VMWare Fusion to do both.
OK, that means your sample was mangled by the formatting on EE.
Please post the sample as a file, so the line breaks aren't modified.
Please post the sample as a file, so the line breaks aren't modified.
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that's great, thanks for getting down to the bottom of the problem.
Open in new window
with the replacementOpen in new window
will take care of the <b> tags, leaving only the line breaks to be solved.HTH,
Dan