Anyone REALLY good with regular expressions?
#1
Anyone REALLY good with regular expressions?
Hi Chaps
I have a major headache regular expression to do.
I want to search through html and replace a string with another string.
Except...
I don't want it to replace it when it's part of a html tag.
In addtion, string should only be replaced if it is a whole word
If the string to search for is "AAA" and the string to replace it with is "BBB" the following...
<a href="AAA">AAA</a> AAA XAAA <b>AAA. XAAA</b> <img="AAA.jpg">
should change to..
<a href="AAA">AAA</a> BBB XAAA <b>BBB. XAAA</b> <img="AAA.jpg">
---
If you can work it out, you're a FAR better man than I am!
Thanks in advance
Simon
I have a major headache regular expression to do.
I want to search through html and replace a string with another string.
Except...
I don't want it to replace it when it's part of a html tag.
In addtion, string should only be replaced if it is a whole word
If the string to search for is "AAA" and the string to replace it with is "BBB" the following...
<a href="AAA">AAA</a> AAA XAAA <b>AAA. XAAA</b> <img="AAA.jpg">
should change to..
<a href="AAA">AAA</a> BBB XAAA <b>BBB. XAAA</b> <img="AAA.jpg">
---
If you can work it out, you're a FAR better man than I am!
Thanks in advance
Simon
#2
If you have Dreamweaver MX (using a reg exp search/replace) then this worked on your test data above:
Search string: ([^a-zA-Z0-9"])AAA([^a-zA-Z0-9<])
Replease string: $1BBB$2
If you want to post or PM me some better data so I can test/refine, please feel free.
J
Search string: ([^a-zA-Z0-9"])AAA([^a-zA-Z0-9<])
Replease string: $1BBB$2
If you want to post or PM me some better data so I can test/refine, please feel free.
J
#5
Scooby Regular
Originally Posted by ScoobySport (SdB)
I don't want it to replace it when it's part of a html tag.
Is it just hyperlinks you want to avoid matching? The regex above will break if there happens to be a space after a matching token. For completeness it will need to avoid all anchor tags.
Steve
Thread
Thread Starter
Forum
Replies
Last Post
Mattybr5@MB Developments
Full Cars Breaking For Spares
33
29 August 2017 07:18 PM
Sambob
Engine Management and ECU Remapping
41
27 November 2015 07:36 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
20
22 October 2015 06:12 AM