python - In regular expressions, if the second half of the matched string happens to be the first half of the next matched string, how to implement it?
给我你的怀抱
给我你的怀抱 2017-06-12 09:27:43
0
1
867

I was reviewing the re module recently, and suddenly I thought of this question, that is, if the second half of the matched string happens to be the first half of the next matched string, how to achieve it? For example, there is a string nowaAFDdADDdDFDsDFS, and I want to match the lowercase letters d, d and s surrounded by three uppercase letters. My code is as follows:

import re rawstring = 'aAFDdADDdDFDsDFS' reg = r'[^A-Z]*[A-Z]{3}([a-z]+)[A-Z]{3}[^A-Z]*' pattern = re.compile(reg) r = pattern.finditer(rawstring) for s in r: print(s.group())

The results obtained are as follows:

aAFDdADDd DFDsDFS

The second d is missing. What should I do if I want to match the second d as well? Thanks!

给我你的怀抱
给我你的怀抱

reply all (1)
给我你的怀抱

r'(?<=[A-Z]{3})([a-z])(?=[A-Z]{3})'

>>> import re >>> rawstring = 'aAFDdADDdDFDsDFS' >>> reg = r'(?<=[A-Z]{3})([a-z])(?=[A-Z]{3})' >>> pattern = re.compile(reg) >>> pattern.findall(rawstring) ['d', 'd', 's']
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!