regexp widehex glitch

Discussion in 'Ruby' started by Simon Strandgaard, May 19, 2004.

  1. 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
    Simon Strandgaard, May 19, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jluis
    Replies:
    5
    Views:
    1,017
    Ray Andraka
    May 12, 2004
  2. rajan

    making a glitch filter

    rajan, Mar 8, 2005, in forum: VHDL
    Replies:
    2
    Views:
    8,005
    Ulf Samuelsson
    Mar 13, 2005
  3. Replies:
    4
    Views:
    926
    radarman
    Apr 22, 2006
  4. Blade

    A glitch?

    Blade, May 20, 2005, in forum: HTML
    Replies:
    3
    Views:
    644
    Blade
    May 21, 2005
  5. Joao Silva
    Replies:
    16
    Views:
    355
    7stud --
    Aug 21, 2009
Loading...

Share This Page