Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Anyone REALLY good with regular expressions?

Thread Tools
 
Search this Thread
 
Old 09 June 2004, 03:06 PM
  #1  
ScoobySport (SdB)
Scooby Regular
Thread Starter
 
ScoobySport (SdB)'s Avatar
 
Join Date: May 2004
Posts: 252
Likes: 0
Received 0 Likes on 0 Posts
Default 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
Old 09 June 2004, 03:32 PM
  #2  
judgejules
Scooby Regular
 
judgejules's Avatar
 
Join Date: Nov 2000
Posts: 1,227
Likes: 0
Received 0 Likes on 0 Posts
Default

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
Old 09 June 2004, 04:04 PM
  #3  
ScoobySport (SdB)
Scooby Regular
Thread Starter
 
ScoobySport (SdB)'s Avatar
 
Join Date: May 2004
Posts: 252
Likes: 0
Received 0 Likes on 0 Posts
Default

Hi judgejules

Thanks a million... I'm using php. Will test now.

brb

Cheers

Simon
Old 09 June 2004, 04:15 PM
  #4  
ScoobySport (SdB)
Scooby Regular
Thread Starter
 
ScoobySport (SdB)'s Avatar
 
Join Date: May 2004
Posts: 252
Likes: 0
Received 0 Likes on 0 Posts
Default

sent you some code by pm
Old 10 June 2004, 12:52 AM
  #5  
stevencotton
Scooby Regular
 
stevencotton's Avatar
 
Join Date: Jan 2001
Location: behind twin turbos
Posts: 2,710
Likes: 0
Received 1 Like on 1 Post
Default

Originally Posted by ScoobySport (SdB)
I don't want it to replace it when it's part of a html tag.
But the text between the <b>'s is part of an HTML tag, as indeed is the entire document

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
Related Topics
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
blackandz
General Technical
0
12 September 2015 07:01 PM



Quick Reply: Anyone REALLY good with regular expressions?



All times are GMT +1. The time now is 07:14 PM.