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

    extracting string using Regex in Javascript

    From this string:
    "(EVAL)(H:somestring)Other Text here"

    I need to extract (H:somestring) and somestring into variables where somestring will could be and set of characters.

    Below is not working.


    Code:
    <script type="text/javascript">
    var x = "(EVAL)(H:pines)Some other Text here";
    alert(x.match(/H\:(.*?)/g));	
    </script>
    Thanks for any help or information.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by cyberpine View Post
    I need to extract (H:somestring) and somestring into variables where somestring will could be and set of characters.
    Clear as mud. Please clarify. I am guessing what you require.

    Code:
    <script type="text/javascript">
    var x = "(EVAL)(H:pines)Some other Text here";
    var a = (x.match(/(H\:[^:\)]*)/g));	
    alert (a);  // H:pines
    var b = a[0].replace(/.*:/,"");
    alert (b);  // pines
    var y = x.replace(/.*\)/g,"")
    alert (y);// Some other Text here
    </script>
    Last edited by Philip M; 12-08-2009 at 07:59 PM.


  •  

    Posting Permissions

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