Py学习  »  Python

python中使用re的部分字符串匹配

Shaunak • 3 年前 • 1371 次点击  

在python中匹配所有小写字母,这些字母后跟两个或更多大写字母,然后是三个或更多数字:(匹配中不应包括大写字母和数字)

我试过了,但没有成功:[a-z]?![A-Z]{2,}[0-9]{3,}。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/128111
 
1371 次点击  
文章 [ 1 ]  |  最新文章 3 年前
Tim Biegeleisen
Reply   •   1 楼
Tim Biegeleisen    3 年前

使用您当前的方法,但将大写字母和数字放在积极的展望中:

[a-z](?=[A-Z]{2,}[0-9]{3,})

这种模式意味着:

[a-z]          match a lowercase letter
(?=            then lookahead (but do NOT consume)
    [A-Z]{2,}  2 or more uppercase letters
    [0-9]{3,}  followed by 3 or more digits
)

看啊 明确肯定 ,但不是 消费 ,以正则表达式模式。