我应该用什么正则表达式来匹配这样的文本
/product="hypothetical protein"".
到目前为止,我已经厌倦了这个模式:
x = re.match(r"^s*\=product(.*)",line)"
使用
import re
test_str = ' /product="hypothetical protein"'
match = re.search(r'product="([^"]+)"', test_str)
if match:
print(match.group(1))
参见正则表达式证明。
--------------------------------------------------------------------------------
product=" 'product="'
--------------------------------------------------------------------------------
( group and capture to 1:
--------------------------------------------------------------------------------
[^"]+ any character except: '"' (1 or more
times (matching the most amount
possible))
--------------------------------------------------------------------------------
) end of 1
--------------------------------------------------------------------------------
" '"'