Fairly new to regex, looking to identify a user id pattern that is all alpha, is exactly 6 characters, and the second character is always a Z. Any help would be appreciated.
Asked
Active
Viewed 32 times
-4
-
1Welcome to Stack Overflow! SO is not a free code-writing service. Instead, show us what you've tried, and where *specifically* in that attempt you're getting stuck. It would also be helpful to know which language you're using to apply the pattern matching, as different languages implement slightly different "flavors"/specifications of RegExp that could impact answers. – esqew Jun 11 '20 at 14:47
-
Give us an example what you expect from a text as output – Makusium Jun 11 '20 at 14:47
-
[a-zA-Z]{1}\Z[a-zA-Z]{4} maybe – Alberto Sinigaglia Jun 11 '20 at 14:48
-
https://regex101.com/r/eIiFY6/1 – Robert Harvey Jun 11 '20 at 14:52
2 Answers
0
How about this regex:
\w(Z|z)\w{4}
Is this what you want?
Chris Ruehlemann
- 15,379
- 3
- 11
- 27
-
that doesn't find a match, an example would be bzh7wv. *Edit* It can include digits 1-9. – Josh Dixon Jun 11 '20 at 15:02
-
But you said the second char was always a "Z" (upper case!) Have edited the answer – Chris Ruehlemann Jun 11 '20 at 15:18
0
As I understood you want something to detect something like this:
jZabcd
What you could do is something like this:
[A-Za-z][Z]([A-Za-z]{4})
Breakdown:
[A-Za-z] = detects all alpha big and small letters only once.
[Z] = checks if there is only a big "Z".
() = a group to make it easier.
{4} = checks if there is 4 times from what was infront of the 4.
[A-Za-z]{4} = checks if there are 4 letters from big A-Z and small a-z.
I hope this helps you out and please expand your question next time a little more.
Makusium
- 126
- 1
- 14
-
Check out this https://stackoverflow.com/questions/4923380/difference-between-regex-a-z-and-a-za-z for what `A-z` actually matches! – Chris Ruehlemann Jun 11 '20 at 17:37
-
@ChrisRuehlemann thank you kind sir! Damn now I need to change all my codes from earlier projects...better now than later. – Makusium Jun 11 '20 at 20:31
-