So, I'd like to check if a string of letters and digits is in correct format
Here's what it needs to look like:
123abc#456def#
I've tried something like that:
Regex r = new Regex(@"^([0-9a-zA-Z]#)([0-9a-zA-Z]#)$");
Didn't help me...
So, I'd like to check if a string of letters and digits is in correct format
Here's what it needs to look like:
123abc#456def#
I've tried something like that:
Regex r = new Regex(@"^([0-9a-zA-Z]#)([0-9a-zA-Z]#)$");
Didn't help me...
As I mentioned in the comments you need to quantify your sets as such: [0-9a-zA-Z]{6}
^([0-9a-zA-Z]{6}#)([0-9a-zA-Z]{6}#)$
You can also do ^([0-9a-zA-Z]{6}#){2}$
since .net keeps multiple captures (not just the last one). See this shorter regex in use here. Click on Table and under the heading $1
expand 2 captures
For ensuring 3 numbers followed by 3 letters use either of the following patterns:
^(\d{3}[a-z]{3}#)(\d{3}[a-z]{3}#)$
^(\d{3}[a-z]{3}#){2}$
And add IgnoreCase
option
I would go for the following regex:
^([A-Za-z0-9]{6}#){2}$
But you didn't specify the format of your strings, so It's actually a guess game. Are those hash-delimited groups only recurring two times? Do you want to match 3 numbers followed by 3 letters in each group?