Ruby, regexp: what is \r and \f? [duplicate] - ruby

This question already has answers here:
What are carriage return, linefeed, and form feed?
(13 answers)
Closed 8 years ago.
All I found again and again was this:
[\s\t\r\n\f] \s Whitespace character
Two questions:
I know that \n is new line, \t is tab, but what is \r and \f?
How do I search for them? What keyword should I use in Google?

carriage return and form feed respectively. As for how to google, "whitespace characters" worked for me

Related

How to split a string by space and newline in Golang? [duplicate]

This question already has answers here:
Split a string on whitespace in Go?
(4 answers)
Closed 10 months ago.
I'm a beginner in Golang and I want to split a multiline text terminated by the EOF indicator, and I want to do it by the space and the presence of new lines ( since the user is gonna press "enter" a lot ).
Any idea of how?
Use strings.Fields
words := strings.Fields(someString)
See example in The Go Playground

Is there a difference between `[^\b]` and `.`? [duplicate]

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

When trying to escape apostrophe with 'gsub', I get backreference [duplicate]

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".

How to find a newline in VSCode? [duplicate]

This question already has answers here:
Find and replace with a newline in Visual Studio Code
(11 answers)
Closed 6 years ago.
I can replace some text with \n if i enable the regex by clicking the regex icon next to the find input box.
But when i try to find a newline, i can't get it to work. I tryed to find \n and [\n]. But none worked. The only solution which worked was [\s] but it's not ideal. But for now it better then nothing i guess.
Is it possible to find a newline in VSCode?
It would depend on the new line settings of your system, but in general on windows a new line is made from two characters, a carriage return \r followed by linefeed \n.
So the regex for a new line is \r\n

Search and replace string in unix bash regex [duplicate]

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}

Resources