What regex should I use for matching such text
JavaScript
x
2
1
/product="hypothetical protein"".
2
by far I have tired this pattern:
JavaScript
1
2
1
x = re.match(r"^s*\=product(.*)",line)"
2
Advertisement
Answer
Use
JavaScript
1
6
1
import re
2
test_str = ' /product="hypothetical protein"'
3
match = re.search(r'product="([^"]+)"', test_str)
4
if match:
5
print(match.group(1))
6
See regex proof.
EXPLANATION
JavaScript
1
13
13
1
--------------------------------------------------------------------------------
2
product=" 'product="'
3
--------------------------------------------------------------------------------
4
( group and capture to 1:
5
--------------------------------------------------------------------------------
6
[^"]+ any character except: '"' (1 or more
7
times (matching the most amount
8
possible))
9
--------------------------------------------------------------------------------
10
) end of 1
11
--------------------------------------------------------------------------------
12
" '"'
13