How to write regexp which will validate the following strings?

68 Views Asked by At

I have tried following regexp in cpp ^((T[X-Z]|R[X-Z])+?)(?:,\\s*|$). It validates only TX. If empty string it should be invalid, it should not accept numbers as well

User may enter:

  1. TX
  2. TX, TY
  3. TX, TY, TZ,
  4. RX, RY, RZ
  5. RX

It should be valid in all cases.

1

There are 1 best solutions below

4
On BEST ANSWER

For the test cases that you put here,([TR][XYZ])(,( )?)? might work.

I have tested it for you here (Mention that global and multiline flags are enabled)