I check a string with a Regex for its valid structure and format.
The Regex I use:
^(?!.+(more|enough|less)+$)(^(?:more|enough|less))[a-z_,]+$
The 1st part of the Regex says: do not end with one of the labels and without whitespace.
The 2nd part of the Regex says: start with one of the labels followed by any characters => and here is the problem I have! The rule must be: Start with one of the labels, followed by any characters. Additionally the other labels may appear again, but only once, and they must begin with a ",".
The format and structure of the string can contain a "," as delimiter and follows the rule:
- [[more|enough|less{topic}][_{aspect}]
- [[more|enough|less{topic}][{aspect}],[[more|enough|less{topic}][{aspect}]
Whereby the label more, enough and less may only be contained once in the string.
My Regex works for nearly all combinations, except:
- lesschips,lessfish
- lesschipsmorebier_cold
For testing I use the following combinations:
- morefish
- morefish_fried
- lesschips
- morebier_cold,lesschips,enoughwater
- lesschips,morebier_cold
... and the following invalid combinations:
- more
- morefish => the example ends with a whitespace
- morefish
- moreless
- lessmore
- leschips
- lesschips,lessfish
- lesschipsmorebier_cold
- morebier_cold,lesschips,enough