python - regex between some character -
input:
[1] string1 [2] string 2[3]string3 [5]string4
output:
string1 string 2 string 4
how resolve case "input" , result "output" "regex" python?
your instructions bit vague, said - using example input provided:
import re line = '[1] string1 [2] string 2[3]string3 [5]string4' matches = re.match(r'\[1\] (.*?)\[2\] (.*?)\[3\](.*?)\[5\](.*)', line) print matches.group(1) # prints string1 print matches.group(2) # prints string 2 print matches.group(3) # prints string3 print matches.group(4) # prints string4
Comments
Post a Comment