This question already has answers here:
Emacs - regular expressions in Lisp need to be double-escaped - why?
(4 answers)
Closed 4 years ago.
I want to search for an regular expression with the function re-search-forward
When I tried using the examples from the page
here: https://www.emacswiki.org/emacs/RegularExpression#toc1
specifically the regular expression \w\{20,\} used to search for a word with 20 letters or more, I get an error.
Here I am placing my cursor after the closing parenthesis in my Lisp buffer and pressing C-x C-e for evaluating it.
However, when I use the Regexp I-search via,
C-M-s it highlights the correct word as expected.
Why is this?
This regexp:
\w\{20,\}
is expressed in a double-quoted elisp string like so:
"\\w\\{20,\\}"
Backslashes are special to the double-quoted read syntax for strings as well as being special to regexp syntax; so if a backslash is for the regexp, you need to double it.
Related
This question already has answers here:
PL/SQL, how to escape single quote in a string?
(5 answers)
Closed 10 months ago.
Insert into mytable (English_Name, French_Name)
Values('Contact Center', 'Centre d'appels')
This would not work since the special French Character d'.
Could someone help me?
The problem is caused by the single-quote character, since single-quote has special meaning - it is used to indicate the beginning and the end of a hard-coded text literal.
Simplest: you need to use TWO single-quote characters to generate one such character in the output (in this case: in the value stored in the table).
Cleaner: Use the q-quote mechanism (google for the term, if you had not heard of it before). Like this:
insert ... values ( ... , q'[Centre d'appels]')
Notice q'[ for opening and ]' for closing the text literal.
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 answers here:
Where is Ruby's string literal juxtaposition feature officially documented?
(4 answers)
Closed 7 years ago.
I am surprised by some string concatenation I've stumbled upon in a codebase I support. Why, or how really, does the following manage to concatenate two strings together?
queue_name = 'gen-request-' "#{ENV['USERNAME'].gsub('.','')}"
=> "gen-request-robertkuhar"
I had expected to see a '+' between the two strings, but its not there. Is it implied or something?
I know this just makes more sense with up-the-middle string interpolation. Thats not what I'm asking. I want to know what it is about the language syntax that allows this to work in the first place.
This only works for string literals, and a part of the literal syntax.
If you have 2 string literals with just whitespace between them, they get turned into a single string. It's a convention borrowed from later versions of C.
This question already has answers here:
How to escape all characters with special meaning in Regex
(2 answers)
Closed 7 years ago.
I know this might be asked time and again. But I'm really stuck with this. I've got it to work for including numbers and alphabets but I have no idea on how to include "/" also.
This is what I have,
name.gsub!(/[^0-9A-Za-z]/, '')
So if name is "Cool Stuff *(#/" it returns "CoolStuff". I'd just like it to return "CoolStuff/".
The / is a special character that must be 'escaped' (meaning to take the / literally, and not for a switch or special meaning). So you have:
name.gsub!(/[^0-9A-Za-z]/, '')
But also realize you could shorten your RegEx statement by making it case insensitive by adding an 'i' after the ending slash and therefore allowing you to drop either the [A-Z] or the [a-z] part. So you could have instead:
name.gsub!(/[^0-9A-Z\/]/i, '')
Hope this helps!
This question already has answers here:
What are <-- Ruby Strings called? And how do I insert variables in them?
(3 answers)
Closed 8 years ago.
Can someone tell me the name of
<<-MAP
STRING HERE
MAP
operator (<<-) in ruby? I tried search for 'double less than' but it didn't turn up anything. I want to learn more about it but don't even know what it's called!
Thanks
Thats called the here doc syntax .Generally used to enter multiline strings. You can read about it here http://blog.jayfields.com/2006/12/ruby-multiline-strings-here-doc-or.html
and also here The <<- operator on Ruby, where is it documented?
It's not an operator, it's a here document (aka heredoc) String literal. It works more or less like heredocs in other languages.
It is specified in section 8.7.6.3.6 of the ISO Ruby Language Specification.