470,580 Members | 2,345 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,580 developers. It's quick & easy.

Help with regular expression

Rob
Hello all,

I have the folowing string
"url(http://www.somelocation/anaywhere/image.jpg)" stored in the variable
str_image
and I want to extract the string between the brackets.
I have

ar_match=str_image.match("url([.]*)");

it returns
0=url
1=

How do I get this to work?

thanks in advance Rob

Jul 20 '05 #1
4 1505
Rob wrote:
Hello all,

I have the folowing string
"url(http://www.somelocation/anaywhere/image.jpg)" stored in the
variable str_image
and I want to extract the string between the brackets.
I have

ar_match=str_image.match("url([.]*)");


I'd do:

var strURI = str_image.replace(/^url\(|\)$/ig, "$1");
--
Andrew Urquhart
- FAQ: http://jibbering.com/faq
- Archive: http://groups.google.com/groups?grou...ang.javascript
- Reply: www.andrewu.co.uk/about/contact/
Jul 20 '05 #2
Rob

"Andrew Urquhart" <re***@website.in.sig> schreef in bericht
news:Gh***************@newsfe2-gui.server.ntli.net...
Rob wrote:
Hello all,

I have the folowing string
"url(http://www.somelocation/anaywhere/image.jpg)" stored in the
variable str_image
and I want to extract the string between the brackets.
I have

ar_match=str_image.match("url([.]*)");


I'd do:

var strURI = str_image.replace(/^url\(|\)$/ig, "$1");
--
Andrew Urquhart
- FAQ: http://jibbering.com/faq
- Archive: http://groups.google.com/groups?grou...ang.javascript
- Reply: www.andrewu.co.uk/about/contact/

From now on I do the same ... ;-)

thanks Rob
Jul 20 '05 #3
rh
"Rob" <reply_@news_group.please> wrote in message news:<S1******************@amsnews05.chello.com>.. .
"Andrew Urquhart" <re***@website.in.sig> schreef in bericht
news:Gh***************@newsfe2-gui.server.ntli.net...
Rob wrote:
Hello all,

I have the folowing string
"url(http://www.somelocation/anaywhere/image.jpg)" stored in the
variable str_image
and I want to extract the string between the brackets.
I have

ar_match=str_image.match("url([.]*)");


I'd do:

var strURI = str_image.replace(/^url\(|\)$/ig, "$1");
--
Andrew Urquhart
- FAQ: http://jibbering.com/faq
- Archive: http://groups.google.com/groups?grou...ang.javascript
- Reply: www.andrewu.co.uk/about/contact/

From now on I do the same ... ;-)

thanks Rob


Note that the "$1" is extraneous in the replacement string, since
there are no capturing parentheses in the RegExp literal (not that any
are desired in this case).

The slight modification:

var strURI = str_image.replace(/^url\(|\)$/ig, "");

seems likely to be as Andrew intended to present.
Jul 20 '05 #4
rh wrote:
The slight modification:

var strURI = str_image.replace(/^url\(|\)$/ig, "");

seems likely to be as Andrew intended to present.


Oops, $1 is a force of habit, thanks rh :-)
--
Andrew Urquhart
- FAQ: http://jibbering.com/faq
- Archive: http://groups.google.com/groups?grou...ang.javascript
- Reply: www.andrewu.co.uk/about/contact/
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Steve | last post: by
5 posts views Thread by Bradley Plett | last post: by
4 posts views Thread by Neri | last post: by
6 posts views Thread by JohnSouth | last post: by
1 post views Thread by Rahul | last post: by
3 posts views Thread by Zach | last post: by
14 posts views Thread by Chris | last post: by
3 posts views Thread by Mr.Steskal | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.