Closed
Bug 543318
Opened 16 years ago
Closed 16 years ago
Regular expression converts '-' (minus) into hex code 0x01 (start of heading)
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: the_djmaze, Unassigned)
Details
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.6) Gecko/20091216 Fedora/3.5.6-1.fc11 Firefox/3.5.6
Build Identifier: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.6) Gecko/20091216 Fedora/3.5.6-1.fc11 Firefox/3.5.6
When running a regular expression to match certain characters to escape them.
It converts the minus sign into hex code 0x01
Reproducible: Always
Steps to Reproduce:
format = '%d-%m';
alert(format.replace(/([\-\.\(\)])/g,'\\\1'));
Actual Results:
%d\%m
Expected Results:
%d\-%m
Comment 1•16 years ago
|
||
You want $1 in the replacement string, not \1:
js> alert=print
function print() {[native code]}
js> format = '%d-%m';
"%d-%m"
js> alert(format.replace(/([\-\.\(\)])/g,'\\\1'));
%d\%m
js> RegExp.$1
"-"
js> RegExp.$2
""
js> RegExp.$_
"%d-%m"
js> alert(format.replace(/([\-\.\(\)])/g,'\\$1'));
%d\-%m
/be
Status: UNCONFIRMED → RESOLVED
Closed: 16 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•