neha mundokar
neha mundokar

Reputation: 1

How to write regexp which will validate the following strings?

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.

Upvotes: -2

Views: 69

Answers (1)

Farbod Ahmadian
Farbod Ahmadian

Reputation: 747

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)

Upvotes: 0

Related Questions