Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > oniguruma : can't get it to search for \ (backslash)

Reply
Thread Tools

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

 
 
Dean Holdren
Guest
Posts: n/a
 
      06-26-2007
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"

 
Reply With Quote
 
 
 
 
Daniel Lucraft
Guest
Posts: n/a
 
      06-26-2007
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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Oniguruma... Hal Fulton Ruby 4 01-06-2006 09:51 PM
Oniguruma -- when? rubyhacker@gmail.com Ruby 6 12-07-2005 11:47 PM
[Brainstorming Input] Ruby-Oniguruma interoperability on Named Groups Wolfgang Nádasi-Donner Ruby 8 07-31-2005 04:28 PM
look-behind in oniguruma Phil Tomson Ruby 5 09-12-2004 11:32 AM
regexp unlimited: Ruby's vs Oniguruma Simon Strandgaard Ruby 2 11-17-2003 04:05 AM



Advertisments