Since OP clearly described the details for cell phone pattern, I've just code it in the pattern.
Let's just forget about the open bracket after 0? at the moment
"0?3" = start with 0 or without 0 and followed by 3, ? represents 1 or none of character before it.
those special characters are called "Meta characters", e.g [ ] - \ * ? n ^ $ ( ) | + , holding special meaning.
(0[0-9]|1[1-6]|2[1-5]|3[1-6]|4[1-7])
0 with 0 to 9 or
1 with 1 to 6 or
2 with 1 to 5 or
3 with 1 to 6 or
4 with 1 to 4
Pipe represnets "or" and brackets make a group, so 0?3 floowed by either one of such combination as OP described.
-?\d{7} = with or without hyphen followed by 7 digits of any numbers
\d represents numbers and \D is oppsite(non numeric character)
{7} represents 7 character of before it.
You can also make it loike {6,7}, means 6 to 7 characters, or {6,} means more than 6 characters
So that the pattern satisfied all the possible combination that OP described.
Then you can refer the position of retrieved string using Brackets using "submatches" property.
If you look at the pattern and the first open bracket is closing at the end.
That means submatches(0), index for submatches begins with 0, refers without first "0", because we only need that part of the string and we can add "0" to it afterwards.
Otherwise, we will have problem if the string has "0".
This is rough explanation and you can google about the keywords like
VBA Regualr Expressions Meta Character
etc.
Bookmarks