SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regex get number (id) in a string(url) with different format

    Hi,
    What's the best way to do this:
    Code JavaScript:
    var re = /(\d+)/,
    urls = [
        'http://www.emp-online.it/bin/shop.php?prog=shop&funktion=PRODUCTINFO&article=670017',
        'http://www.emp-online.it/art_670017/'
    ],len = urls.length;
    for(var i = 0; i < len; i++){
        var match = re.exec(urls[i]);
        if(match[1]!==null){
            console.log(match[1]);
        }
    }

    Bye

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    How about by using .match() instead?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •