Arkinghor
Arkinghor

Reputation: 1

Select all after specific word javascript regex

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

Answers (4)

musefan
musefan

Reputation: 48415

You don't need regex for this...

var str = "AlertID=234423";
var val = str.substring(str.indexOf("=") + 1);
//val = 234423

Here is a working example

Upvotes: 0

nkmol
nkmol

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

jsFiddle

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388316

You don't have look behind in javascript

 alert($str.match(/ID=(\d+)/)[1]);

Upvotes: 1

anubhava
anubhava

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

Related Questions