bugzilla.mozilla.org has resumed normal operation. Attachments prior to 2014 will be unavailable for a few days. This is tracked in Bug 1475801.
Please report any other irregularities here.

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

RESOLVED FIXED

Status

Rhino
Core
RESOLVED FIXED
12 years ago
7 years ago

People

(Reporter: Marc, Unassigned)

Tracking

Details

(Reporter)

Description

12 years ago
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

Comment 1

10 years ago
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(", "));

Comment 2

7 years ago
My patch in pull request #19 ( https://github.com/mozilla/rhino/pull/19 ) will fix this bug.

Comment 3

7 years ago
I merged Masami's pull request.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → FIXED

Updated

7 years ago
Duplicate of this bug: 448443

Updated

7 years ago
Duplicate of this bug: 543663
You need to log in before you can comment on or make changes to this bug.