Closed
Bug 1360352
Opened 8 years ago
Closed 8 years ago
String.match fails when regex String or RegExp(String) passed
Categories
(Firefox :: Untriaged, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: jmichae3, Unassigned)
Details
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.
Comment 1•8 years ago
|
||
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
Closed: 8 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•