Welcome to WebmasterWorld Guest from 23.21.38.201

Forum Moderators: open

web expression regular expressions

using find and replace

   
12:22 pm on May 12, 2011 (gmt 0)

5+ Year Member



wonder if anyone knows if its possible to use regular expressions on both the find and the replace element. In short if i want to find all occurrences of:
[0-9] million
where [0-9] is any number in that set
and replace only the sign to something else, can it be done. I dont see how the replace element can be specified to only replace the with say a $ and leave the number part untouched.
7:56 pm on May 12, 2011 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



You have to capture the number in the "find" part:
([0-9]+)
with + to allow for inflation ;)

and then call it
$1
in the "replace" part.
8:13 am on May 13, 2011 (gmt 0)

5+ Year Member



tx but i cant get this to work.
how exactly should the $1 be written, ($1)? well ive tried all combos but none work, i.e. [$1] , ([$1]), ([0-9]$1) etc.
:(
10:00 am on May 13, 2011 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



No, no, it's just $1.

Parentheses mean "hang on to this text". $1 (and $2, $3 and so on if you're being fancy) mean "now spit it out again".

For example-- pulling something out of my own htaccess-- in

RedirectMatch 301 /paintings/blowups/(\w+)/(?:large)?(\w+)\.html$ /paintings/$1/$2.html


the first parenthesized bit goes into the $1 slot, and the second bit goes into the $2 slot, so

/paintings/blowups/rats/harpo.html


becomes

/paintings/rats/harpo.html


or

/paintings/blowups/cats/largedixie.html


becomes

/paintings/cats/dixie.html



I do not actually have pages with these names.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month