Use regular expressions:
import re
for line in open('m.txt'):
match = re.search('uniprotkb:P(\d+)', line)
if match:
print match.group(1)
More Related Contents:
- How t extract last part of a text in python [duplicate]
- re.findall not returning full match?
- re.sub replace with matched content
- Searching for IP addresses in a file
- How to understand regular expression with python?
- Escaping regex string
- Fast punctuation removal with pandas
- Python regex matching Unicode properties
- Python: How to match nested parentheses with regex?
- How do you validate a URL with a regular expression in Python?
- python re.sub group: number after \number
- Handling backreferences to capturing groups in re.sub replacement pattern
- Python regular expressions – how to capture multiple groups from a wildcard expression?
- Regex matching between two strings?
- Regex: AttributeError: ‘NoneType’ object has no attribute ‘groups’
- remove unicode emoji using re in python
- Python – RegEx for splitting text into sentences (sentence-tokenizing) [duplicate]
- Re.match() returns always none
- How to use regular expression in lxml xpath?
- replacing only single instances of a character with python regexp
- Why isn’t the regular expression’s “non-capturing” group working?
- Python Regular Expression Match All 5 Digit Numbers but None Larger
- Python regular expression for HTML parsing
- Remove Sub String by using Python
- Type of compiled regex object in python
- How does python and the regex module handle backslashes?
- How to tell if one regular expression matches a subset of another regular expression?
- match dates using python regular expressions
- How to Fix JSON Key Values without double-quotes?
- How to use regex with optional characters in python?