Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  55] [ 6]  / answers: 1 / hits: 18447  / 14 Years ago, mon, august 9, 2010, 12:00:00

I wrote a regular expression which I expect should work but it doesn't.


var regex = new RegExp('(?<=[)[0-9]+(?=])')

JavaScript is giving me the error:



Invalid regular expression :(/(?<=[)[0-9]+(?=])/): Invalid group



Does JavaScript not support lookahead or lookbehind?


More From » regex

 Answers
-3

This should work:



var regex = /[[0-9]+]/;




edit: with a grouping operator to target just the number:



var regex = /[([0-9]+)]/;


With this expression, you could do something like this:



var matches = someStringVar.match(regex);
if (null != matches) {
var num = matches[1];
}

[#95978] Friday, August 6, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marinal

Total Points: 655
Total Questions: 99
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;