- 论坛徽章:
- 0
|
两个问题:
1.要匹配整行,是不是用match更合适。
match从字符串的开头开始匹配,如果开头位置没有匹配成功,就算失败了;而search会跳过开头,继续向后寻找是否有匹配的字符串。
2.正则表达式中:r'[^(]+([^,]*)\*([^,]*)' 中的[^,]是不是又包含了(
用这个试试:r'[^(]*\*+[^(]*'- import re
- _regexp_compile_cache = {}
- def Search(pattern, s):
- """Searches the string for the pattern, caching the compiled regexp."""
- if pattern not in _regexp_compile_cache:
- _regexp_compile_cache[pattern] = re.compile(pattern)
- return _regexp_compile_cache[pattern].match(s)
- readline = 'bool DimeterOmc::writeLog( int code_id, const char* log_desc, ...)'
- # typedef bool (*DYNCHECKFUNC)();'''
- match_point = Search(r'[^(]*\*+[^(]*', readline)
- print match_point.group(0)
复制代码 |
|