Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > regexp widehex glitch

Reply
Thread Tools

regexp widehex glitch

 
 
Simon Strandgaard
Guest
Posts: n/a
 
      05-19-2004
Within regexp's you can match a hexbyte by typing '\x42'

irb(main):001:0> /\x20/.match("z z").to_a
=> [" "]
irb(main):002:0>


However with ruby-1.9 plus UTF-8 enabled

server> ruby -v
ruby 1.9.0 (2004-05-17) [i386-freebsd5.1]
server> irb
irb(main):001:0> str = [0x70, 0x80, 0x90].pack('U*')
=> "p\302\200\302\220"
irb(main):002:0> $KCODE = 'U'
=> "U"
irb(main):003:0> /\x{80}/
SyntaxError: compile error
(irb):3: Invalid escape character syntax
/\x{80}/
^
(irb):3: unterminated string meets end of file
(irb):3: syntax error
/\x{80}/
^
from (irb):3
irb(main):004:0> /\\x{80}/.match(str)
=> nil
irb(main):005:0> Regexp.new('\x{80}') =~ str
=> 1
irb(main):006:0>

What seems absurd to me is that Ruby's builtin / ... / syntax cannot deal
with \x{80} while Regexp.new has no problems with it.

I guess this is a problem in Ruby's / ... / syntax?

--
Simon Strandgaard


 
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
new RegExp().test() or just RegExp().test() Matěj Cepl Javascript 3 11-24-2009 02:41 PM
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
Ruby 1.9 - ArgumentError: incompatible encoding regexp match(US-ASCII regexp with ISO-2022-JP string) Mikel Lindsaar Ruby 0 03-31-2008 10:27 AM
Programmatically turning a Regexp into an anchored Regexp Greg Hurrell Ruby 4 02-14-2007 06:56 PM
RegExp.exec() returns null when there is a match - a JavaScript RegExp bug? Uldis Bojars Javascript 2 12-17-2006 09:59 PM



Advertisments