Help with regular expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob

    Help with regular expression

    Hello all,

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

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

    it returns
    0=url
    1=

    How do I get this to work?

    thanks in advance Rob



  • Andrew Urquhart

    #2
    Re: Help with regular expression

    Rob wrote:[color=blue]
    > Hello all,
    >
    > I have the folowing string
    > "url(http://www.somelocatio n/anaywhere/image.jpg)" stored in the
    > variable str_image
    > and I want to extract the string between the brackets.
    > I have
    >
    > ar_match=str_im age.match("url([.]*)");
    >[/color]

    I'd do:

    var strURI = str_image.repla ce(/^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/


    Comment

    • Rob

      #3
      Re: Help with regular expression


      "Andrew Urquhart" <reply@website. in.sig> schreef in bericht
      news:GhE1c.512$ sq2.484@newsfe2-gui.server.ntli .net...[color=blue]
      > Rob wrote:[color=green]
      > > Hello all,
      > >
      > > I have the folowing string
      > > "url(http://www.somelocatio n/anaywhere/image.jpg)" stored in the
      > > variable str_image
      > > and I want to extract the string between the brackets.
      > > I have
      > >
      > > ar_match=str_im age.match("url([.]*)");
      > >[/color]
      >
      > I'd do:
      >
      > var strURI = str_image.repla ce(/^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/
      >
      >[/color]


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

      thanks Rob


      Comment

      • rh

        #4
        Re: Help with regular expression

        "Rob" <reply_@news_gr oup.please> wrote in message news:<S1F1c.586 07$KL3.7841@ams news05.chello.c om>...[color=blue]
        > "Andrew Urquhart" <reply@website. in.sig> schreef in bericht
        > news:GhE1c.512$ sq2.484@newsfe2-gui.server.ntli .net...[color=green]
        > > Rob wrote:[color=darkred]
        > > > Hello all,
        > > >
        > > > I have the folowing string
        > > > "url(http://www.somelocatio n/anaywhere/image.jpg)" stored in the
        > > > variable str_image
        > > > and I want to extract the string between the brackets.
        > > > I have
        > > >
        > > > ar_match=str_im age.match("url([.]*)");
        > > >[/color]
        > >
        > > I'd do:
        > >
        > > var strURI = str_image.repla ce(/^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/
        > >
        > >[/color]
        >
        >
        > From now on I do the same ... ;-)
        >
        > thanks Rob[/color]

        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.repla ce(/^url\(|\)$/ig, "");

        seems likely to be as Andrew intended to present.

        Comment

        • Andrew Urquhart

          #5
          Re: Help with regular expression

          rh wrote:[color=blue]
          > The slight modification:
          >
          > var strURI = str_image.repla ce(/^url\(|\)$/ig, "");
          >
          > seems likely to be as Andrew intended to present.[/color]

          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/


          Comment

          Working...