0

Ruby 1.8.7 says:

/Users/user/.thor/916bf40c98406efffe9700e1ef02da24:194: undefined (?...) sequence: /(?<text>Version:)\s*(?<version>[\d\.]+)/

Ruby 1.9.3-p374 says something similar, but Ruby 1.9.3-p0 works just fine with it.

The actual code that's broken:

pattern = /(?<text>Version:)\s*(?<version>[\d\.]+)/

What am I doing wrong ?

3
  • How about - what did I do wrong with the pattern ? Commented Apr 29, 2013 at 16:23
  • Don't use regex for HTML, use nokogiri or a similar, dedicated parser instead Commented Apr 29, 2013 at 16:23
  • 1
    Not parsing HTML. I'm parsing a CSS file with very predictable content "Version: 10.10.10" for example. Commented Apr 29, 2013 at 16:25

2 Answers 2

2

The (?<k>...) notation expresses named capture, which was introduced in Ruby 1.9, which uses Oniguruma regex engine. With Ruby 1.8, you need to either change the regex to not use it, or install Oniguruma or Onigmo (an improved version of Oniguruma introduced in Ruby 2.0).

Sign up to request clarification or add additional context in comments.

4 Comments

But why did I get an error in 1.9.3-p374 then ? I assumed I had something wrong with my regex there.
I think what is happening is as what Darshan writes.
Thank you for the answer. Updated ruby, everything works out fine.
Good. I hope you updated to Ruby 2.0 because there is less reason to not switch from 1.9 to 2.0 than not to switch from 1.8 to 1.9.
2

Your code works fine for me in Ruby 1.9.3-p374. I suspect that what you are doing wrong is still running 1.8.7 when you think you're using 1.9.3-p374. As noted by @sawa, your regex is using a feature introduced in 1.9.

1 Comment

That was weird. Now after a couple of rvm implodes I've managed to get everything straight. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.