I am attempting to match a value like 'MN+WI' at the end of a URL, for example /foos/MN+WI. The pattern [a-zA-Z][\+\,]? produces a match result of MN+WI on rubular.com, but in IRB:
s="MI+WI"
p="[a-zA-Z]{2}[\+\,]?"
r=Regexp.new(p)
r.match(s) # => #<MatchData "MI+">
The behavior in Ruby console is consistent with what I am encountering with Rails. Is there a difference between the two? How do I need to adjust my regex pattern?
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0]
$ rails -v
Rails 4.0.0
** edit **
Original pattern should have been [a-zA-Z]{2}[\+\,]?.
What I really need to have a route recognize any of these variations and assign it to a param:
MN(working)mn(working)MN+WI(not working)MN+WI+IA(arbitrary number of 2-letter value, separated by a+)- not match single or more than 2-letter values (e.g.
ABC), but keep 2-letter values (e.g.ABC+MN; keepMN)
[a-zA-Z][\+\,]?does not match MN+WI.