Simple RegEXP HELP!
Posted: Fri Apr 29, 2011 2:50 pm
Hey guys,
I am having trouble with a Javascript regular expression. I am using the match function and results output are wrong.
Here is my code:
The result are:
addfriend.php?id=1\"
addfriend.php?id=2\"
addfriend.php?id=3\"
I would like the result to only be:
1
2
3
What is wrong with my code? How could it only select the id number?
Thanks guys!
I am having trouble with a Javascript regular expression. I am using the match function and results output are wrong.
Here is my code:
Code: Select all
<script language="javascript" type="text/javascript">
string = 'addfriend\.php\?id=1\\\" |||||| addfriend\.php\?id=2\\\" |||||| addfriend\.php\?id=3\\\" ';
result = string.match(/addfriend\.php\?id=(\d*)\\\"/gi);
for (i=0; i < result.length; i++) {
document.write(result[i] + '<br>');
}
</script>addfriend.php?id=1\"
addfriend.php?id=2\"
addfriend.php?id=3\"
I would like the result to only be:
1
2
3
What is wrong with my code? How could it only select the id number?
Thanks guys!