I’m just wondering if it’s possible to use one regular expression to match another, that is some sort of:
['a-z'].match(['b-x'])
True
['m-n'].match(['0-9'])
False
Is this sort of thing possible with regex at all? I’m doing work in python, so any advice specific to the re module’s implementation would help, but I’ll take anything I can get concerning regex.
Edit: Ok, some clarification is obviously in order! I definitely know that normal matching syntax would look something like this:
expr = re.compile(r'[a-z]*')
string = "some words"
expr.match(string)
<sRE object blah blah>
but I’m wondering if regular expressions have the capability to match other, less specific expressions in the non-syntacticly correct version I tried to explain with above, any letter from b-x would always be a subset (match) of any letter from a-z. I know just from trying that this isn’t something you can do by just calling the match of one compiled expression on another compiled expression, but the question remains: is this at all possible?
Let me know if this still isn’t clear.
I think — in theory — to tell whether regexp
Amatches a subset of what regexpBmatches, an algorithm could:Band also of the “union”A|B.However, it would likely be a major project to do this in practice. There are explanations such as Constructing a minimum-state DFA from a Regular Expression but they only tend to consider mathematically pure regexps. You would also have to handle the extensions that Python adds for convenience. Moreover, if any of the extensions cause the language to be non-regular (I am not sure if this is the case) you might not be able to handle those ones.
But what are you trying to do? Perhaps there’s an easier approach…?