0

I have a project for searching for bytecode instructions and I would like to expand it to allow the use of Regular Expressions for matching patterns.

The gist of what I want to do is have custom character classes/sets so I can have something such as ISTORE match any of the following instructions:

ISTORE ISTORE_0 ISTORE_1 ISTORE_2 ISTORE_3

And then something similar for ILOAD ... ILOAD_n etc.

ISTORE and ILOAD would be similar to metacharacters like \s where they truly stand for multiple characters.

Basically I am just looking for a jumping off point so I can find a way to implement my own metacharacters.

4

1 回答 1

2

您不需要修改正则表达式引擎(这将非常困难)

您只需要一个辅助函数即可将您的正则表达式风格转换为 python 的风格,就像您使用的一样re.escape

def my_re_escape(regex):
    regex = re.escape(regex)
    regex = regex.replace('foo', 'bar')
    # etc
    return regex
于 2013-09-03T20:24:44.237 回答