Regular expression pattern /[]]/ not match right square bracket.

RESOLVED DUPLICATE of bug 272395

Status

()

Core
JavaScript Engine
RESOLVED DUPLICATE of bug 272395
13 years ago
13 years ago

People

(Reporter: Anthony Howe, Unassigned)

Tracking

1.8 Branch
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

13 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.8) Gecko/20051111 Firefox/1.5
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.8) Gecko/20051111 Firefox/1.5

JavaScript regular expressions are based on Perl compatible regular expressions, which in turn are based on POSIX extended regular expressions. The pattern:

  /[]]/

should match a right square bracket in a string like "text [text] text". The pattern fails to match. See Single Unix Specification, chapter 9.3.5 RE Bracket Expression, point 1, paragraph 1:

http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_03_05

It would appear that the pattern:

  /[\]]/

will match a right square bracket, but is not standard nor historical practice with respect to regular expressions.

I found this while trying to perform a replacement to quote RE special characters:

  var quoted = string.replace(/([][{}().?/\+*^$|])/g, "\\$1");

The current workaround is to escape the right square bracket within character class:

  var quoted = string.replace(/([\][{}().?/\+*^$|])/g, "\\$1");


Reproducible: Always

Steps to Reproduce:

Updated

13 years ago
Assignee: nobody → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → general
Version: unspecified → 1.8 Branch

Comment 1

13 years ago

*** This bug has been marked as a duplicate of 272395 ***
Status: UNCONFIRMED → RESOLVED
Last Resolved: 13 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.