Matching a pattern in python
pattern = "F-x-([EK])-x-S-([GT])-R-T" pattern=pattern.replace("-","") pattern=pattern.replace("x","[GPAVLIMCFYWHKRQNEDST]") count=0 for sequence in source: count += 1 sequence=sequence.replace(" ","") result = re.finditer(pattern, sequence) print(">sequence ",count) print(sequence) for match in result: print("found ",match.group()," at position",match.span()," third position =", match.group(2))
Source: bpc.biobix.be
python pattern matching example
import re pattern = re.compile('[a-zA-Z ]+') # a...z A...Z and space allowed message = "Weather is nice" if pattern.match(message).group() == message: print("match") else: print("no match")