Javascript + Regex newbie question

G

GCoder

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??
 
P

petermichaux

GCoder said:
...[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
 
T

Thomas 'PointedEars' Lahn

Dr said:
[...] (e-mail address removed) 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Regex replace problem 2
JavaScript Regex 19
regex question 7
Replacement Problem 1
Issue with textbox script? 0
TF-IDF 1
question about speed of sequential string replacement vs regex or 15
Regex 3

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top