Hi,
I have a big long web page, with lots of web addresses in - e.g:
<a href="http://www.google.co.uk/search?q=mysql+ ... -8">Google for MySQL Tutorials</a>
Would it be possible to do a find and replace, using a reg ex which finds all ampersands contained within the hyperlinks in any <a href> tags, and replace them with "&"?
Thanks
Jim
Reg Ex Find and Replace help
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
How about this multi-step solution:
(as ever, use POSIX regular expression syntax)
Search : (<a href.*)\x26(.*>)
Replace with: \1###amp;\2
[X] Regular expression
Repeatedly using "Replace All" will substitute all ampersands (Hex 26), within an <a href > line, for "###amp;".
When no more matches are found, then:
Search : ###
Replace with: &
[ ] Regular expression
Hope this helped.
(as ever, use POSIX regular expression syntax)
Search : (<a href.*)\x26(.*>)
Replace with: \1###amp;\2
[X] Regular expression
Repeatedly using "Replace All" will substitute all ampersands (Hex 26), within an <a href > line, for "###amp;".
When no more matches are found, then:
Search : ###
Replace with: &
[ ] Regular expression
Hope this helped.
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
(<a href.*)\x26(.*>) or, more simply, (<a href.*)&(.*>) does not match just <a> tags containing ampersands. It matches everything from an <a href to the last > on the same line, provided there's an ampersand in between. So it will replace ampersands within the bodies of single-line <a> elements and between <a> elements on the same line as well as ampersands in <a> tags. This is not what the original poster asked for.
You might try changing .* into [^<>]*
You might try changing .* into [^<>]*