-4

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.

  • 1
    Welcome 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 Answers2

0

How about this regex:

\w(Z|z)\w{4}

Is this what you want?

Chris Ruehlemann
  • 15,379
  • 3
  • 11
  • 27
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