# Oniguruma : can't get it to search for \\ (backslash)

**URL:** <https://www.ruby-forum.com/t/oniguruma-cant-get-it-to-search-for-backslash/107864>\
**Category:** Ruby\
**Created:** [June 26, 2007, 11:25pm UTC](https://www.ruby-forum.com/t/oniguruma-cant-get-it-to-search-for-backslash/107864 "2007-06-26T23:25:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![deanhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df705f/32.png) [@deanhiller](https://www.ruby-forum.com/u/deanhiller)\
**Post date:** [June 26, 2007, 11:25pm UTC](https://www.ruby-forum.com/t/oniguruma-cant-get-it-to-search-for-backslash/107864/1 "2007-06-26T23:25:40Z")

</div>

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  
from /usr/local/lib/ruby/site\_ruby/1.8/oniguruma.rb:177:in  
`old_initialize' from /usr/local/lib/ruby/site_ruby/1.8/oniguruma.rb:177:in`initialize’  
from (irb):43:in `new’  
from (irb):43  
from /usr/local/lib/ruby/site\_ruby/1.8/oniguruma.rb:359

For arguments sake, with just one backslash:  
irb(main):044:0\> reg = Oniguruma::ORegexp.new(’’)  
irb(main):045:1’  
(with just one back-slash, irb sees unfinished syntax)

Same if I use double-quotes:  
irb(main):046:0\> reg = Oniguruma::ORegexp.new("\")  
ArgumentError: Oniguruma Error: end pattern at escape  
from /usr/local/lib/ruby/site\_ruby/1.8/oniguruma.rb:177:in  
`old_initialize' from /usr/local/lib/ruby/site_ruby/1.8/oniguruma.rb:177:in`initialize’  
from (irb):46:in `new’  
from (irb):46  
from /usr/local/lib/ruby/site\_ruby/1.8/oniguruma.rb:359

Double quotes with just one backslash:  
irb(main):047:0\> reg = Oniguruma::ORegexp.new("")  
irb(main):048:1"

---

<div class="post-metadata">

**Author:** ![deanhiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df705f/32.png) [@deanhiller](https://www.ruby-forum.com/u/deanhiller)\
**Post date:** [June 26, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/oniguruma-cant-get-it-to-search-for-backslash/107864/2 "2007-06-26T23:51:36Z")

</div>

Dean H. 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
