I am parsing the script line by line to find the following pattern "print("xxxx") or "LOG.info("xxxx").
SeacrhOutput = re.search(r'print\(((.*?)\))',line)
sre_constants.error: bad escape \L at position 5
when the LOG.info was added to the pattern re.search(r'print\|LOG.info\(((.*?)\))',line)
Use
(?:print|LOG\.info)\((.*?)\)
See proof . The expression will match print
or LOG.info
with (
after them, and then capture any zero or more characters into a group up to the leftmost )
.
EXPLANATION:
NODE EXPLANATION
--------------------------------------------------------------------------------
(?: group, but do not capture:
--------------------------------------------------------------------------------
print 'print'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
LOG 'LOG'
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
info 'info'
--------------------------------------------------------------------------------
) end of grouping
--------------------------------------------------------------------------------
\( '('
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
.*? any character except \n (0 or more times
(matching the least amount possible))
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
\) ')'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.