...

View Full Version : extracting string using Regex in Javascript



cyberpine
12-08-2009, 08:02 PM
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:pines)Some other Text here";
alert(x.match(/H\:(.*?)/g));
</script>


Thanks for any help or information.

Philip M
12-08-2009, 08:33 PM
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.


<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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum