I want to find all repeating pattersn with start with 1-2degits, contains some text, strange scharacters and numbers and finishes with 4 digits.
For example,
It fineds only one pattern.
If i use
i find 23 patterns, but of course this captures only the beginning of the pattern, i.e. 1-2 digits.
If i add .+, i am finding only one pattern:
I do not know how to mark that any character can be between 1-2 and 4 numbers in the patters. If i use .+ to mark this, when regex captures full text, it does not stop at 4 digits.
Thank you!
For example,
Code:
ref=""" 1. Lieber, C. M. The incredible shrinking circuit. Sci. Am. 285, 58±64 (2001).
2. Cui, Y. & Lieber, C. M. Functional nanoscale electronic devices assembled using silicon nanowire
building blocks. Science 291, 851±853 (2001).
3. Wang, J. F., Gudiksen, M. S., Duan, X. F., Cui, Y. & Lieber, C. M. Highly polarized photolumi-
nescence and photodetection from single indium phosphide nanowires. Science 293, 1455±1457
(2001)."""
quer="\d{1,2}\.\s+.+\(\d{4}\)\."
ansre=re.findall(quer,ref,re.DOTALL)
print(len(ansre))
If i use
Code:
quer="\d{1,2}\.\s+"
If i add .+, i am finding only one pattern:
Code:
quer="\d{1,2}\.\s+\.+"
Thank you!
Comment