mardi 1 décembre 2020

Regex match group with elements in random order

For simplicity sake, let's say I have the following literal string:

abc[4;?;z;*]def

where 4, ?, z and * can appear in random order, are separated by a ; , and are characters (or strings) that i know beforehand.

I have this regex that matches the string using 'or' groups:

abc\[(?:z|\*|4|\?|\;)+\]def

The problem is that is still matching if one of the elements is missing in the string, and I want to check if all are present:

abc[?;z;*]def

Capturing groups are irrelevant for me. I just want to confirm the whole string.




Aucun commentaire:

Enregistrer un commentaire