homepage Welcome to WebmasterWorld Guest from 54.197.111.87
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / WYSIWYG and Text Code Editors
Forum Library, Charter, Moderator: open

WYSIWYG and Text Code Editors Forum

    
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

/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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / WYSIWYG and Text Code Editors
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved