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
    18,144
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts


  •  

    Posting Permissions

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