Answer the question
In order to leave comments, you need to log in
How to write a regular expression to work with a multiline field?
Hello.
There is this text:
anyname 5 {
строка 1
строка 2
}
match[1] = '5'
match[2] = 'Строка 1'
match[3] = 'Строка 2'
reply (\d) {
(.*)
(.*)
}
Answer the question
In order to leave comments, you need to log in
a = re.search(r"(?s)(\d+)\s*{\s*(.*?)}", text)
m = [a.group(1)] + a.group(2).splitlines()
print (m)
/(.+(\d+))/m
Full match - string ("word digit", "many words digit").
The 2nd group in each match is the number after the word in each line.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question