I use the Ruby scan () method to search for text in a specific format. Then I output it to a line separated by commas. The text I'm trying to find will look like this:
AB_ABCD_123456
Here is what I still found to find above. It works great:
text.scan(/.._...._[0-9][0-9][0-9][0-9][0-9][0-9]/)
puts text.uniq.sort.join(', ')
Now I need a regular expression that will find above with or without a two-letter country designation at the end. For example, I would like to find all three of the following:
AB_ABCD_123456
AB_ABCD_123456UK
AB_ABCD_123456DE
I know that I can use two or three different scans to achieve my result, but I wonder if there is a way to get all three with one regular expression.
source
share