Java Script Regular Expressions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dempsey.Jeff@gmail.com

    Java Script Regular Expressions

    I am a wreck at regular expressions so I could use a little help.

    Say I have a url that looks something like this.
    http://test.com/test/test2/tabid/656/Default.aspx. I need to be able
    to pull out only the word test2. I wont know that the word is going
    to be test2 when I use the regular expressions so I need to find
    everything between / and /tabid because that is the only thing that
    will be the same no matter what.

  • Evertjan.

    #2
    Re: Java Script Regular Expressions

    wrote on 14 feb 2008 in comp.lang.javas cript:
    I am a wreck at regular expressions so I could use a little help.
    >
    Say I have a url that looks something like this.
    http://test.com/test/test2/tabid/656/Default.aspx. I need to be able
    to pull out only the word test2. I wont know that the word is going
    to be test2 when I use the regular expressions so I need to find
    everything between / and /tabid because that is the only thing that
    will be the same no matter what.
    <script type='text/javascript'>

    var t = 'http://test.com/test/test2/tabid/656/Default.aspx';

    t = t.replace(/.+\/([^\/]+)\/tabid\/.+/,'$1')

    alert(t);


    </script>

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Gregor Kofler

      #3
      Re: Java Script Regular Expressions

      Dempsey.Jeff@gm ail.com meinte:
      I am a wreck at regular expressions so I could use a little help.
      >
      Say I have a url that looks something like this.
      http://test.com/test/test2/tabid/656/Default.aspx. I need to be able
      to pull out only the word test2. I wont know that the word is going
      to be test2 when I use the regular expressions so I need to find
      everything between / and /tabid because that is the only thing that
      will be the same no matter what.
      Untested:
      /\/(.*?)\/tabid/

      Gregor


      --
      http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
      http://web.gregorkofler.com ::: meine JS-Spielwiese
      http://www.image2d.com ::: Bildagentur für den alpinen Raum

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Java Script Regular Expressions

        Gregor Kofler wrote:
        Dempsey.Jeff@gm ail.com meinte:
        >Say I have a url that looks something like this.
        >http://test.com/test/test2/tabid/656/Default.aspx. I need to be able
        >to pull out only the word test2. I wont know that the word is going
        >to be test2 when I use the regular expressions so I need to find
        >everything between / and /tabid because that is the only thing that
        >will be the same no matter what.
        >
        Untested:
        /\/(.*?)\/tabid/
        Less error-prone because not using the non-greedy subexpression and not
        allowing the empty string:

        /\/[^\/]+\/tabid/


        PointedEars
        --
        var bugRiddenCrashP ronePieceOfJunk = (
        navigator.userA gent.indexOf('M SIE 5') != -1
        && navigator.userA gent.indexOf('M ac') != -1
        ) // Plone, register_functi on.js:16

        Comment

        Working...