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. <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> Code (markup): Thanks for any help or information.
I'm on IE 7. I tried this and it did not work <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)); // without question mark alert(inside); </script> Code (markup): Both produce "(H:somestring)" However, this (aparently without /g for greedy? var inside = (x.match(/\(H\:(.*?)\)/)); // not sure how Code (markup): produces "(H:\somestring),somestring" How do I address the second one? thanks.
I suggest you test your regexp with the online regexp tester. Your regexp has returned both (H:somestring)" and "somestring". (H:somestring) can be extracted in the return of match method. "somestring" submatch can be extracted with RegExp.$1.