Regex code with "or" operator

Hi!

I am working with a regex code which is collecting a String of 12 numbers from a textvariable between 0-9. The code I have is this:

System.Text.RegularExpressions.Regex.Match(textVariable, “[0-9]{12}”).Value

I would like to add the or-operator (||) in this expression due to that sometimes the structure of the numbers differs. The two scenarios is:

  1. xxxxxxxxxxxx (12 numbers in a regular sequence)
  2. xxxxxxxx-xxxx (12 numbers with the character “-” before the last four numbers)

Is this possible, and how should I add this scenario to the existing example above.

Thanks!
/Klara

@Klara,

First replace that ‘-’.

textVariable.replace("-",""). . Then apply regular expression.

1 Like

@lakshman Thank you, that was very helpful!

I have another question for you if you would like to assist.

The next step is to get some information between these numbers and a line break.
Something like this:
System.Text.RegularExpressions.Regex.Match(textVariable,"((?<=Linebreak).*(?=, “+theNumbers+”))").Value

Thank you!
/Klara

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.