Opened 10 years ago
Closed 9 years ago
#1189 closed defect (invalid)
string-substitute \NUM syntax with preceding backslashes
Reported by: | John Foerch | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 4.11.0 |
Component: | extensions | Version: | 4.9.x |
Keywords: | Cc: | ||
Estimated difficulty: |
Description
I'm seeing an odd behavior with string-substitute. I want to prefix commas in a string with backslashes, but found the following behavior:
> (use regex) > (string-substitute #\, "\\ \\0" "a,b") "a\\ ,b" > (string-substitute #\, "\\\\0" "a,b") "a\\\\0b"
The \NUM syntax in the substitution string worked as expected when preceded by a space, but not when preceded by another backslash (which was escaped).
CHICKEN version 4.9.0.1
regex version 1.0
Change History (2)
comment:1 Changed 9 years ago by
Milestone: | someday → 4.11.0 |
---|
comment:2 Changed 9 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
This seems to be an undocumented feature of the substring-replace function, which allows you to escape the backslash. I would recommend using irregex, the regex egg's API is kind of deprecated anyway, and it's also not very efficient.
Here's how to do this using irregex:
#;1> (use irregex) #;2> (irregex-replace #\, "a,b" "\\" 0) "a\\,b"
You can also use irregex-replace/all if you want to replace more than just the first occurance.
This is an interesting bug, I would like to see what's causing this for 4.11