Welcome to WebmasterWorld Guest from 188.8.131.52 , register , free tools , login , search , subscribe , help , library , announcements , recent posts , open posts Subscribe to WebmasterWorld
web expression regular expressions using find and replace santapaws msg:4311276 12:22 pm on May 12, 2011 (gmt 0) 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.
lucy24 msg:4311529 7:56 pm on May 12, 2011 (gmt 0)
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. santapaws msg:4311707 8:13 am on May 13, 2011 (gmt 0)
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. :( lucy24 msg:4311738 10:00 am on May 13, 2011 (gmt 0)
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
I do not actually have pages with these names.