Home > Mobile >  regex to validate i/p string as PDC-<GroupName>-Team1 or PDC-<GroupName>-Team2 or PDC-&l
regex to validate i/p string as PDC-<GroupName>-Team1 or PDC-<GroupName>-Team2 or PDC-&l

Time:10-12

I have to build such a regex where I can validate the i/p string should be in format...

PDC--Team1 or PDC--Team2 or PDC--Team3

GroupName can be any alphanumeric string with only "-" allowed to use.

I am currently trying with ^PDC-[A-Za-z0-9-] -Team1$|[A-Za-z0-9-] -Team2$|[A-Za-z0-9-] -Team3$ but this not working as expected..

If someone knows how to this let me know

CodePudding user response:

Something like this should work for you:

^PDC-[A-Za-z0-9-]*-Team[0-9]$

So we start with PDC-, capture anything in between and end with -Team and a number.

I guessed that groups can go higher than 3, else change the last group to [1-3], If it can go higher than 9 then add a * after the group for any number.

CodePudding user response:

I found it somehow working with ^PDC-[a-zA-Z0-9-]*-(Team1|Team2|Team3)$. Just still the enhancement is to allow PDC- only at start and only for single time.

  • Related