Hi, I am relatively new to regex and have a simple question. I want to find two words within a string (and everything in between to the two words and replace it with something else. The specific string is: ....[lots of text]..................thumbnailUrl=xxxxxxxxxxxxxxxxx&..........................[more text] i want to snip out the everything in between and including thumbnailUrl= and the & and all the text in between the two words. The text between the two words is not a constant number and contains the % sign. This is what I was thinking but its not working properly: foo = foo.replace(/[thumbnailUrl=.*]-[&]/i, 'replacement text'); Can someone please help??
GCoder wrote: > > ...[lots of > text]..................thumbnailUrl=xxxxxxxxxxxxxxxxx&..........................[more > text] > > This is what I was thinking but its not working properly: > > foo = foo.replace(/[thumbnailUrl=.*]-[&]/i, 'replacement text'); I think you want foo = foo.replace(/thumbnailUrl=.*?&/,"replacement text") Maybe you still want the 'i' flag too if thumbnailUrl might be capitalized differently. - Peter
![]() |
0 |
![]() |
JRS: In article <1144991557.121655.73250@e56g2000cwe.googlegroups.com>, dated Thu, 13 Apr 2006 23:14:08 remote, seen in news:comp.lang.javascript, petermichaux@gmail.com posted : > >foo = foo.replace(/thumbnailUrl=.*?&/,"replacement text") > foo = foo.replace(/thumbnailUrl=[^?]*&/, "replacement text") may be safer. -- � John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 � <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources. <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
![]() |
0 |
![]() |
Dr John Stockton wrote: > [...] petermichaux@gmail.com posted : >> foo = foo.replace(/thumbnailUrl=.*?&/,"replacement text") > > foo = foo.replace(/thumbnailUrl=[^?]*&/, "replacement text") > > may be safer. But not equivalent. Peter proposed non-greedy matching. Probably you meant foo = foo.replace(/thumbnailUrl=[^&]*&/, "replacement text") PointedEars
![]() |
0 |
![]() |