www.webdeveloper.com
Results 1 to 6 of 6

Thread: Regular Expressions problem

  1. #1
    Join Date
    Sep 2010
    Posts
    6

    Regular Expressions problem

    This problem has made me gone insane and cant seem to fix it...although I am a complete noob when it comes to regular expressions.

    I basically want to match the numbers at the end of the following string:
    Code:
    <input type="checkbox" id="4_23_check" value="off" style="float:left;line-height:24;" />23
    which would return "23"

    I know this is probably super simple, I tried doing
    Code:
    var re = "/\/>(.*?)/";
    var newStrings = theBigStringAbove.match(re);
    But couldn't get er' jump started. Any assistance would be awesome!

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,364

    Lightbulb Something to try ...

    I'm not exactly sure this is what you are trying to do, but here goes ...
    Code:
    <html>
    <head>
    <title>regExp Match</title>
    </head>
    <body>
    
    <script type="text/javascript">
    // From: http://www.webdeveloper.com/forum/showthread.php?t=236106
    
    var str =  '<input type="checkbox" id="4_23_check"'
        str += ' value="off" style="float:left;line-height:24;" />23';
    
    var re = /\d\d$/;
    var newStrings = str.match(re);
    alert(str+'\n'+re+'\n'+newStrings);
    
    </script>
    </body>
    </html>

  3. #3
    Join Date
    Sep 2010
    Posts
    6
    Thanks for the reply. It is part of what I need.
    For that particular string it works but I will also have various other values after the <input ... />, example:
    "Rob's Clothes"
    or
    United States 3
    etc.
    So I pretty much need everything after that.

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,364

    Wink Something else to try ...

    Quote Originally Posted by linewirefx View Post
    Thanks for the reply. It is part of what I need.
    For that particular string it works but I will also have various other values after the <input ... />, example:
    "Rob's Clothes"
    or
    United States 3
    etc.
    So I pretty much need everything after that.
    Another shot ...
    Code:
    <html>
    <head>
    <title>regExp Match</title>
    </head>
    <body>
    
    <script type="text/javascript">
    // From: http://www.webdeveloper.com/forum/showthread.php?t=236106
    
    var re = />.*$/;
    
    var str =  '<input type="checkbox" id="4_23_check"'
        str += ' value="off" style="float:left;line-height:24;" />23';
    
    var newStrings = str.match(re);
    alert(str+'\n'+re+'\n'+newStrings[0].substring(1));
    
        str = "< other stuff>Robin's Clothes";
        newStrings = str.match(re);
    alert(str+'\n'+re+'\n'+newStrings[0].substring(1));
    
        str = "< other stuff> United States 3";
        newStrings = str.match(re);
    alert(str+'\n'+re+'\n'+newStrings[0].substring(1));
    
    </script>
    </body>
    </html>

  5. #5
    Join Date
    Sep 2010
    Posts
    6
    Yes sir, thank you much : )

  6. #6
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,364

    Thumbs up

    Quote Originally Posted by linewirefx View Post
    Yes sir, thank you much : )
    You're most welcome.
    Happy to help.
    Good Luck!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles