regular expression help finding href within window.open()

Discussion in 'Javascript' started by jd, Apr 11, 2007.

  1. jd

    jd Guest

    hi all,

    i'm using regular expression to find the url of the page to be opened
    using the window.open().

    typical urls look like this http://domain.com/path-to-page.html

    right now i'm trying href.match(/http:\/\/domain\.com\/\w?\.html/)

    and this will get me http://domain.com/path but not everything to
    html.

    does anyone have some tips they can offer?

    i've tried
    href.match(/http:\/\/domain\.com\/\w*\.html/)
    href.match(/http:\/\/domain\.com\/*\.html/)

    and they don't work.

    thanks for any help you can offer
    jd, Apr 11, 2007
    #1
    1. Advertising

  2. jd

    Cah Sableng Guest

    On Apr 11, 6:31 am, "jd" <> wrote:
    > hi all,
    >
    > i'm using regular expression to find the url of the page to be opened
    > using the window.open().
    >
    > typical urls look like thishttp://domain.com/path-to-page.html
    >
    > right now i'm trying href.match(/http:\/\/domain\.com\/\w?\.html/)
    >


    '-' character is not word characters, so it \w won't make it.
    Use '-' with \w enclosed by square bracket, and prepend '-' with '\'
    because it is regex's special character.

    try:
    /^http:\/\/domain\.com\/[\w\-]+\.html/
    Cah Sableng, Apr 11, 2007
    #2
    1. Advertising

  3. jd

    RobG Guest

    On Apr 11, 11:35 am, "Cah Sableng" <> wrote:
    > On Apr 11, 6:31 am, "jd" <> wrote:
    >
    > > hi all,

    >
    > > i'm using regular expression to find the url of the page to be opened
    > > using the window.open().

    >
    > > typical urls look like thishttp://domain.com/path-to-page.html

    >
    > > right now i'm trying href.match(/http:\/\/domain\.com\/\w?\.html/)

    >
    > '-' character is not word characters, so it \w won't make it.
    > Use '-' with \w enclosed by square bracket, and prepend '-' with '\'
    > because it is regex's special character.
    >
    > try:
    > /^http:\/\/domain\.com\/[\w\-]+\.html/


    Presumably the domain name is in a string of other stuff and will be
    enclosed in quotes, so maybe:

    /http:[^\'\"]+\.html/

    will suit better.


    --
    Rob
    RobG, Apr 11, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,281
  2. bus105
    Replies:
    2
    Views:
    80
    Evertjan.
    Dec 2, 2003
  3. saiho.yuen
    Replies:
    3
    Views:
    416
    kaeli
    Sep 14, 2004
  4. fatted
    Replies:
    4
    Views:
    137
    fatted
    Aug 21, 2003
  5. Saya
    Replies:
    1
    Views:
    131
    Ben Morrow
    Jan 16, 2004
Loading...

Share This Page