#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    5
    Rep Power
    0

    Extracting string and removing it and it's wrapper


    I want to extract "(H:somestring" and "somestring" based on that it follows (H: and is closed by ). Can I do this with match in javascript?


    Code:
    <script type="text/javascript">
    var x = "(EVAL)(H:somestring)Some other Text here";
    var full =(x.match(/\(H\:(.*?)\)/g));	
    alert(full);
    var inside = (x.match(/\(H\:(.*?)\)/g)); // not sure how
    alert(inside);
    </script>
    Thanks.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Location
    Norcross, GA
    Posts
    8
    Rep Power
    0
    This looks like a job for groups.

    Groups let you wrap parts inside of your regex pattern in parenthesis, and extract them as "groups". For example, you could have a regex to match a 10 digit phone number, and have a group inside to also extract the area code.

    I'm a newbie here so I can't post links, but if you google "javascript regex match groups" you'll find some helpful info.

IMN logo majestic logo threadwatch logo seochat tools logo