Using Ruby to scan through a string
- by nekosune
I am trying to create a regex to gather info from strings that look like this:
A22xB67-E34...
for any number.
I have the regex:
@spaceCode = "[A-Z]([A-Z0-9][0-9]|[0-9])"
@moveCode=/^(?<one>#{@spaceCode})((?<mode>x|\-)(?<two>#{@spaceCode}))+$/
However I get:
s="A11-A22xA33".scan(@moveCode)
=> [["A11", "11", "xA33", "x", "A33", "33"]]
which is most definatly NOT what I want.
The string could be any length of C22 etc, with either x or - as the seperator, and put it into an array like:
['A22','x',B22','-'.......]
Examples:
"A22xB23-D23xE25" => ['A22','x','B23','=','D23','E25;]
"AA2xA9-A1" => ['AA2','x','A9','-','A1']