Type of compiled regex object in python

后端 未结 10 1072
一个人的身影
一个人的身影 2020-11-30 07:14

What is the type of the compiled regular expression in python?

In particular, I want to evaluate

isinstance(re.compile(\'\'), ???)

10条回答
  •  隐瞒了意图╮
    2020-11-30 07:55

    FYI an example of such code is in BeautifulSoup: http://www.crummy.com/software/BeautifulSoup and uses the 'hasattr' technique. In the spirit of the "alternative approach", you might also encapsulate your string search in a regexp by doing this: regexp = re.compile(re.escape(your_string)) therefore having a list of only regular expressions.

提交回复
热议问题