How can I extract:
- A string with n digits (say 10) that ends with a letter (say "A"), for example: 4024204455A
- A 12-digit number, for example: 192345006905
using a regex, from multiple text files with Go (golang)?
How can I extract:
using a regex, from multiple text files with Go (golang)?
You could match either 12 digits [0-9]{12}
or 10 digits and an uppercase character [0-9]{10}[A-Z]
using an or |
in a non capturing group (?:
for example:
^(?:[0-9]{12}|[0-9]{10}[A-Z])$
Or match your values between word boundaries \b
:
\b(?:[0-9]{12}|[0-9]{10}[A-Z])\b
To match one or more digits OR 10 digits followed by an uppercase character your could use this regex with word boundaries or anchored $^
: