Closed Bug 369860 Opened 17 years ago Closed 13 years ago

RegExp: non capturing group doesn't working correctly (?:xxx)

Categories

(Rhino Graveyard :: Core, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: mguillemot, Unassigned)

References

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
Build Identifier: 1.6R5

Rhino RegExp doesn't behave correctly (at least not like RegExp in Firefox or in Java). It seems that not capturing group is not interpreted correctly.

Reproducible: Always

Steps to Reproduce:
var re = new RegExp("(?:<script.*?>)(.*)<\/script>")
var t = 'foo <script>boo();</script>bar'
var r = re.exec(t)
if (r[1] != "boo();")
	throw "Bad result: " + r[1]
else
	println("ok")




Sadly the RegExp is too tighly binded to String what makes impossible to just define own version of RegExp based on Java 1.4 regex
Another example from Rhino 1.7:

var str = "<xy";
var matches = str.match(/(?:<<)xy/);
print(matches.join(", "));

matches should be null but is actually ["<xy"].

Make the group a capturing group and things work as expected.

var str = "<xy";
var matches = str.match(/(<<)xy/);
print(matches.join(", "));
My patch in pull request #19 ( https://github.com/mozilla/rhino/pull/19 ) will fix this bug.
I merged Masami's pull request.
Status: UNCONFIRMED → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.