Capturing subset of a string using Python's regex -
Capturing subset of a string using Python's regex -
i have string looks this:
>bounded_rna_of:1ddl:elength : 1
regex wise can formed way:
>bounded_rna_of:(\w+):(\w)length : 1
at end of day want extract 1ddl
, e
.
but why regex failed?
import re seq=">bounded_rna_of:1ddl:elength : 1" match = re.search(r'(>bounded_rna_of:(\w+):(\w)length : 1)',seq) print match.group() # prints this: # >bounded_rna_of:1ddl:elength : 1
what's way it?
this due global catching parenthesis, should grab 2 needed elements.
import re seq=">bounded_rna_of:1ddl:elength : 1" match = re.search(r'>bounded_rna_of:(\w+):(\w)length : 1',seq) print match.group(1), match.group(2)
python regex
Comments
Post a Comment