This question already has answers here:
Why does String#gsub double content?
(3 answers)
Closed 5 years ago.
I have this code:
"1'2".gsub("'","\\'")
Instead of "1\'2", I get: "122". Why?
You need to use this:
puts "1'2".gsub("'","\\\\'")
It is because "\\'" means the context following the match, which is "2".
Related
This question already has answers here:
What does the XML syntax with a colon mean?
(1 answer)
How does XPath deal with XML namespaces?
(2 answers)
Closed 2 years ago.
I found the selector "//svg:path" in inkscape source code, but can't find any reference about single colon in XPath. I found for double colon but not useful for this case.
It is in line 117 on this file
This question already has answers here:
Reference - What does this regex mean?
(1 answer)
\B+ vs [\B]+ vs [^\b]+ in Python regex
(2 answers)
What's the use of the [\b] backspace regex?
(3 answers)
Closed 5 years ago.
Is there a difference between [^\b] and .?
I was modifying some code created by someone else that included this no-word-boundary-character-class ([^\b]). and am not able to find a difference between that and wildcard . (this is in ruby).
My assumption was that [^\b]+ when applied to the string hello world should match hello and stop before the space, (as that is where there is a word boundary.
My observation is that it seems to just match everything. rubular link.
What should be happening here?
[\b] means backspace and [^\b] not a backspace
\b is not a character, it can't be included in a character class.
The negation of a word boundary is \B
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 8 years ago.
What does this Ruby regex mean?
/.../
This regex matches any three characters.
This question already has answers here:
ruby operator "=~" [duplicate]
(3 answers)
Closed 9 years ago.
I was wondering if anyone could explain what the =~ operator does in Ruby. I have seen it a few times but am unable to find a proper explanation of it.
It is used to match Regexes against strings:
http://www.ruby-doc.org/core-2.0.0/Regexp.html#method-i-3D-7E
It returns either a Integer value of the first occurrence in the string or if the expression doesn't match the String it returns nil.
This question already has answers here:
Replacing some characters in a string with another character
(6 answers)
Closed 9 years ago.
Does anyone have an idea on how to search and replace in a string? Let's say for example I have a string
string=".blah http://google.com.ph/tabs/1.5.8 setup https://yahoo.com.ph/root/blah"
I want to search for version 1.5.8 and then replace it with 1.5.9. How do i do it in bash?
instring="version 1.5.8"
outstring=${instring//1.5.8/1.5.9}