Consider the following snippet:
puts 'hello'.gsub(/.+/, '\0 \\0 \\\0 \\\\0')
This prints (as seen on ideone.com):
hello hello \0 \0
This was very surprising, because I'd expect to see something like this instead:
hello \0 \hello \\0
My argument is that \ is an escape character, so you write \\ to get a literal backslash, thus \\...
I have a string, say r"a". I want to replace every r"a" with the string r"\1", but my regex engine does not understand this.
I have tried:
r"\1" -- crashes (can't match group 1 because there is no group 1)
r"\\1" -- crashes (not sure why)
Is this a limitation of my (proprietary) regex engine, or is it a general problem? Is there an ...
Is there a way to modify the value of a backreference?
Example:
In the following Text
"this is a test"
the word 'test' should be extracted and inserted into another text via backrefrence.
Regex:
(test)
Replacement:
"this is another \1"
That works fine so far. But now the question is, if it is possible to modify the backreferen...
I'm having trouble with a regular expression in PHP that uses a potentially empty backreference. I was hoping that it would work as explained in http://www.regular-expressions.info/brackets.html:
If a backreference was not used in a
particular match attempt (such as in
the first example where the question
mark made the first ba...
string.replace(/([\t])/g,"\\$1")
is working fine where
string.replace(/([\n])/g,"\\$1")
is not working!!!
any idea please???
N.B. string.replace(/\n/g,"\\n") is also working fine
...
All,
I've come across an interesting little quirk in one of my RewriteRules, which I wanted to resolve by the use of named back references. However from what I can see, this is not possible in Apache's mod_rewrite.
I have two incoming urls, each containing a key variable, which need to be rewritten to the same underlying framework acti...