RegExp.match() delivers a spurious match

RESOLVED INVALID

Status

()

Core
JavaScript Engine
RESOLVED INVALID
8 years ago
8 years ago

People

(Reporter: Angelo Borsotti, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

8 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4

RegExp.match()when matching a regular expression containing
an alternation delivers an extra match that should not be
delivered.

Reproducible: Always

Steps to Reproduce:
1. open the following page:
<html>
<head>
<script type="text/javascript">
document.write(/(abc|ab)/.exec("abc"));
</script>
</head>
</html>
2. Firefox displays: abc,abc 
Actual Results:  
abc,abc 

Expected Results:  
abc

there is clearly only one occurrence of "abc" in "abc"

Updated

8 years ago
Assignee: nobody → general
Component: General → JavaScript Engine
QA Contact: general → general
exec() returns an array containing the matched text followed by the things all the capturing parentheses in your regexp captured.  If you just want the matched text, use /(?:abc|ab)/.

See ECMA-262 section 15.10.1, 15.10.2.1, and 15.10.6.2
Status: UNCONFIRMED → RESOLVED
Last Resolved: 8 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.