How to tell if one regular expression matches a subset of another regular expression?

前端 未结 7 2278
孤独总比滥情好
孤独总比滥情好 2020-12-01 14:23

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(         


        
7条回答
  •  旧时难觅i
    2020-12-01 15:10

    It's possible with the string representation of a regex, since any string can be matched with regexes, but not with the compiled version returned by re.compile. I don't see what use this would be, though. Also, it takes a different syntax.

    Edit: you seem to be looking for the ability to detect whether the language defined by an RE is a subset of another RE's. Yes, I think that's possible, but no, Python's re module doesn't do it.

提交回复
热议问题