Regex for eact string match

Hi guys,

I’m back with another question/issue.
I have an array of strings and i need to pick only the strings based on this filters: begins with 17, 18, 19, 20 or 21, string is made of numbers only (no special characters like ./-= etc), string length is 10.
Example:
1723421423 this one should be picked
1834567890 this one should be picked
1923421423 this one should be picked
2034567890 this one should be picked
2123421423 this one should be picked

2123421 this one shouldn’t be picked
2123421342. this one shouldn’t be picked
2123421342/ this one shouldn’t be picked
2134567543212123234 this one shouldn’t be picked.
21312412asdasd2341 this one shouldn’t be picked.
21312412a.-sdasd2341 this one shouldn’t be picked.

I’ve tried this Regex mentioned by somebody “\b^[1|2]\d{9}\b” but it picks everything that starts with 1 and 2 and also it picks strings with special characters like this one with a dot at the end “2134565721.”
Can please help me out on this one ?
Much appreciated!!!

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Match(yourString,"^[12]\d{9}(?=\s|$)").Value

Regards,

Tried it but it also takes the numbers starting with 23 24 25 26 27 28 and 29 :frowning:

Hi,

How about the following?

System.Text.RegularExpressions.Regex.Match(yourString,"^(17|18|19|20|21)\d{8}(?=\s|$)").Value

Regards,

1 Like

Works perfect. Much appreciated Yoichi :smiley:

1 Like

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