Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Javascript + Regex newbie question

Reply
Thread Tools

Javascript + Regex newbie question

 
 
GCoder
Guest
Posts: n/a
 
      04-14-2006
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??

 
Reply With Quote
 
 
 
 
petermichaux@gmail.com
Guest
Posts: n/a
 
      04-14-2006

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

 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      04-14-2006
JRS: In article <. com>,
dated Thu, 13 Apr 2006 23:14:08 remote, seen in
news:comp.lang.javascript, 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.
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-16-2006
Dr John Stockton wrote:

> [...] 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
String Pattern Matching: regex and Python regex documentation Xah Lee Java 1 09-22-2006 07:11 PM
Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine? =?Utf-8?B?SmViQnVzaGVsbA==?= ASP .Net 2 10-22-2005 02:43 PM
Java regex imposture re: Perl regex compatibility a_c_Attlee@yahoo.com Java 2 05-06-2005 12:16 AM
perl regex to java regex Rick Venter Java 5 11-06-2003 10:55 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57