String.match fails when regex String or RegExp(String) passed

RESOLVED INVALID

Status

()

RESOLVED INVALID
2 years ago
2 years ago

People

(Reporter: jmichae3, Unassigned)

Tracking

53 Branch
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

2 years ago
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0
Build ID: 20170413192749

Steps to reproduce:

"abcd1234".match(RegExp("/1234/"))


Actual results:

"abcd1234".match("/1234/")
null
"abcd1234".match(/1234/)
Array [ "1234" ]
"abcd1234".match(RegExp("/1234/"))
null


Expected results:

all should have worked, I had thought. at least the last one! only middle one worked.
you're misunderstanding the RegExp syntax and the pattern syntax.
leading and trailing slashes are not part of pattern, and you shouldn't pass it to RegExp constructor.

> "abcd1234".match("/1234/")

when you pass string to String#match, RegExp is created internally with the passed pattern.
so, in this case too, you shouldn't pass "/" there.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.