Skip to content

Instantly share code, notes, and snippets.

@abinoam
Created January 21, 2012 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abinoam/1650955 to your computer and use it in GitHub Desktop.
Save abinoam/1650955 to your computer and use it in GitHub Desktop.
Testing for a possible regexp bug on 1.9.2-290
#!/usr/bin/env ruby
regexp = /^([A-Z]{1,4})([0-9]{1,4})$/
text_phrases =
[ "ABCD1234",
"ABCDE1234",
"ABCD12345",
"ABCDE12345"]
puts RUBY_DESCRIPTION
text_phrases.each do |tp|
match = tp.match regexp
if match
puts "#{tp} matches #{regexp.inspect} capturing: #{match.captures}"
else
puts "#{tp} doesn't match #{regexp.inspect}"
end
end
@straff
Copy link

straff commented Jan 21, 2012

Hi, ran in irb (am Windows) and got below (expected results)
As per http://www.ruby-forum.com/topic/3476712#1041898 when running from Windows cmd it turns out swapping double/single quotes around gave expected behaviour.

ABCD1234 matches /^([A-Z]{1,4})([0-9]{1,4})$/ capturing: ["ABCD", "1234"]
ABCDE1234 doesn't match /^([A-Z]{1,4})([0-9]{1,4})$/
ABCD12345 doesn't match /^([A-Z]{1,4})([0-9]{1,4})$/
ABCDE12345 doesn't match /^([A-Z]{1,4})([0-9]{1,4})$/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment