I need a regular expression to test if strings are in a specific palette of values for example string dir ca only be ltr, rtl, lro, rlo, or another example bool can be only false, true.
What regular expression, can I use to test a string like dir and bool against a limited set of values?
Do you mean something like
'^(ltr|rtl|lro|rlo)$'and'^(true|false)$'?this can even be easily automated:
However, if you leave the line
args = (re.escape(arg) ...)in there, then you really don’t gain anything beyond what you could get usingif arg in myset: .... The beauty of the unescaped version is that you still have at least some of the regex flexibility.