Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript match extract of string?

    Why do I get both the greedy and non-greedy? How do I extract "somestring" only? I'm on IE7.

    thanks

    Code:
    <script type="text/javascript">
    var x = "(EVAL)(H:somestring)Some other Text here";
    var full =(x.match(/\(H\:(.*?)\)/g)); // produces "(H:somestring)" as expected	
    alert(full);
    var inside = (x.match(/\(H\:(.*)\)/)); // produces "(H:somestring),somestring" .. I only 
    
    want "somestring"
    alert(inside);
    </script>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    You were given the answer at

    extracting string using Regex in Javascript


  •  

    Posting Permissions

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