This might be an easy question but I can not get the result that I want!
I have a text like the one below:
text = 'To get to the destination follow this direction
1. First turn left and then
text text text
2. Secondly you have to some text here
some text here
For the second instruction follow the text below:
«1. some text some text some text
text text text.
2. some text some text text text text.
3. some text some text text text text.»'
I am using regex in python and I want to get all the numbers between these characters "«" "»" that is 1. 2. and 3.
I tried something like this:
test = re.findall(r'[«.*?](\d+)[.*?»]', text, re.DOTALL)
or this:
patt = re.findall(r'«.*?(\d+).*?»', text, re.DOTALL)
and many others but none of them return what I want. What am I doing wrong?
Both patterns just return the number 1 without any other digit. What about number 2 and 3?
text = '''To get to the destination follow this direction
1. First turn left and then
text text text
2. Secondly you have to some text here
some text here
For the second instruction follow the text below:
«1. some text some text some text
text text text.
2. some text some text text text text.
3. some text some text text text text.»'''
print re.findall(ur"\d+",re.findall(ur"«([\s\S]*?)»",text)[0])
or
print re.findall(ur"\d+","\n".join(re.findall(ur"«([\s\S]*?)»",text)))
This should do it for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With