Gsub doesn't handle literal #{} well
Reported by Lichorosario | April 12th, 2008 @ 09:27 AM | in 1.6.1
Hi. I think this is a problem:
'#{first}'.gsub(/#{first}/i,'#{second}')
This should return '#{second}', but instead it returns'' (an empty string).
It seems that gsub can't use template-like strings in the replacement.
Comments and changes to this ticket
-
Andrew Dupont April 13th, 2008 @ 10:41 PM
- → State changed from new to open
- → Title changed from Gsub doesn't replace well #{} to Gsub doesn't handle literal #{} well
That's because template-like strings have special meaning in the second argument of gsub. Note the bottom of gsub's API page .
A workaround is to do something like this:
'#{first}'.gsub(/{first}/i,'{second}');We'll look into a better way to handle this — perhaps by allowing you to escape the hash mark. Thanks.
-
Tobie Langel April 16th, 2008 @ 10:11 PM
- → State changed from open to bug_report
-
Tobie Langel April 18th, 2008 @ 01:18 PM
- → State changed from bug_report to bug
-
John-David Dalton May 29th, 2008 @ 04:47 AM
- → Assigned user changed from to Andrew Dupont
- → Milestone changed from to 1.6.1
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
The Prototype JavaScript library.
