c++qtqcomboboxqregexpqvalidator

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.


Solution

  • 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)