Re: oniguruma : can't get it to search for \ (backslash)



Dean Holdren wrote:
I can't seem to get Oniguruma to look for a single backslash, am I
doing anything wrong here?:

I should be able to escape the single with another:
irb(main):043:0> reg = Oniguruma::ORegexp.new('\\')
ArgumentError: Oniguruma Error: end pattern at escape

In a regex literal a backslash is a metacharacter, so you need two
slashes to match a slash: /\\/ But to insert two consecutive slashes in
a string to be compiled into a regex, you need four slashes: "\\\\"

Observe:

irb> reg = Oniguruma::ORegexp.new('\\\\')
=> /\\/

best,
Dan

--
Posted via http://www.ruby-forum.com/.

.



Relevant Pages

  • Re: Help with Regex and trying to mimic the VB "like" comparison
    ... I'd suggest using Regex.Escape(...) to escape all the meta-characters in the ... just allow the pattern the user types be the ... pattern for the regex, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Finding formatting items in a string
    ... I even found a FAQ on this... ... And a further completed regex, including the fact that you can use within the custom pattern if you want to... ... Just escape them again. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to search/match a variable pattern
    ... there are some meta-characters, \:, that I need to escape, but how do I escape ... whether I found a match of a particular string on $path and do not need to ... Or do I get the regex logic all wrong ... ... The one liner is just a test on whether am using the pattern matching correctly ...
    (perl.beginners)
  • Re: How to search/match a variable pattern
    ... upper case both the string and the pattern that I am searching for. ... You probably have regex meta-characters in $pattern that need to be escaped. ...
    (perl.beginners)
  • Re: Regular Expression reserved letters
    ... The problem ist, that e.g.),,are reserved words in regex. ... them in filter expressions i have to escape them with \). ... If, on the other hand, you have a portion of an expresion that must be ... documentation here: <http://java.sun.com/j2se/1.4.2/docs/api/java/util/ ...
    (comp.lang.java.programmer)