Skip to content Skip to sidebar Skip to footer

Regex: How To Match The Set Of A Language's Characters, With Some Exceptions?

Let me use the set of English characters as an example, though the question is really about how to make this work in general for any language's set of characters. I want to write a

Solution 1:

Isn't it very easy to build? Like:

availablelist["en-us"] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
exceptionlist["en-us"] = "cikmovCIKMOV"

regexes["en-us"] = re.compile(f"[{"".join([char in availablelist["en-us"] if char notin exceptionlist["en-us"]])}]")

You can pre-compile every regex you need.

Post a Comment for "Regex: How To Match The Set Of A Language's Characters, With Some Exceptions?"