you seem to be spending a lot of effort on optional spaces. something like \s?
(0 - 1) or \s*
(0 - many) would be better.
also repeating elements separated by something are always complex. it is best to do regexp for the βthingβ to make it easier to repeat.
limit = '\s*([<>]=?|!)\s*\d{1,5}\s*' one_or_more = '^' + limit + '(&' + limit + ')*$'
or, advanced:
^\s*([<>]=?|!)\s*\d{1,5}\s*(&\s*([<>]=?|!)\s*\d{1,5}\s*)*$
also !
is a "sign of relationship", not a "junctor", if I understand correctly.
(for people advocating the use of a "real" parser, the above is the one_or_more
structure - probably, as you end up implementing an & -segment list, there is no need for a parser if you can just use string concatenation in the language).
source share