Reputation: 1
I have problem with this string AlertID=234423. I want select only 234423 how i can do that? I try something like that :
$(document).ready(function() {
var $str = "AlertID=234423"
alert($($str).match("(?<=D=).*"));
alert($str);
});
What i do wrong?
Ok I use this and now is ok:
$forma.match(/ID=(\d+)/)[1]
thanks everyone for help
Upvotes: 0
Views: 998
Reputation: 48415
You don't need regex for this...
var str = "AlertID=234423";
var val = str.substring(str.indexOf("=") + 1);
//val = 234423
Upvotes: 0
Reputation: 8091
If the string is always in the same pattern you can just delete 'AlertID='
:
var str = "AlertID=234423";
str = str.replace('AlertID=', '');
alert(str);
Upvotes: 1
Reputation: 388316
You don't have look behind in javascript
alert($str.match(/ID=(\d+)/)[1]);
Upvotes: 1
Reputation: 785186
Use String#split
:
var r = AlertID=234423'.split('=')[1];
//=> 234423
Or using String#substring
:
var s = 'AlertID=234423';
var r = s.substring(s.indexOf('=')+1);
//=> 234423
Upvotes: 2