infinite loop with regex
Reported by
muriloku...@gmail.com,
Feb 29 2016
|
||
Issue description
Chrome Version : 48.0.2564.116 (Official Build) m (32-bit)
URLs (if applicable) :
Other browsers tested:
Add OK or FAIL, along with the version, after other browsers where you
have tested this issue:
Safari:
Firefox: 44.0.2 FAIL
IE:
What steps will reproduce the problem?
run this code:
var result;
while(result = /my name/g.exec("my name is Murilo.")){
console.log(result)
}
What is the expected result?
A result in console like this: ["my name", index: 0, input: "my name is Murilo."]
What happens instead?
It gets into a infinite loop
Please provide any additional information below. Attach a screenshot if
possible.
This code below works:
var result;
var regex = /my name/g
while(result = regex.exec("my name is Murilo.")){
console.log(result)
}
but if I use /my name/g.exec() it gets into a loop.
,
Mar 1 2016
This is not a bug, please see this post for the reason why http://www.2ality.com/2013/08/regexp-g.html
,
Mar 8 2016
You create a new regex on each iteration, so it starts from scratch and matches the string every time. Not a bug. |
||
►
Sign in to add a comment |
||
Comment 1 by rnimmagadda@chromium.org
, Mar 1 2016Components: Platform>DevTools
Labels: M-50 Type-Bug Pri-2 OS-Linux OS-Mac OS-Windows
Status: Untriaged (was: Unconfirmed)