Type of compiled regex object in python

后端 未结 10 1069
一个人的身影
一个人的身影 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条回答
  •  Happy的楠姐
    2020-11-30 07:50

    This is another not the answer to the question, but it solves the problem response. Unless your_string contains regular expression special characters,

    if re.match(your_string,target_string):
    

    has the same effect as

    if your_string == target_string:
    

    So drop back one step and use uncompiled regular expression patterns in your list of allowed. This is undoubtedly slower than using compiled regular expressions, but it will work with only the occasional unexpected outcome, and that only if you allow users to supply the allowed items

提交回复
热议问题