楼主: hshly
879 11

[问答] 请教一个正则表达式怎么写,谢谢 [推广有奖]

11
xjg 发表于 2018-4-20 10:51:33 |只看作者 |坛友微信交流群
房事不决问百度!
已有 1 人评分热心指数 收起 理由
hshly + 1 精彩帖子

总评分: 热心指数 + 1   查看全部评分

使用道具

12
mao726 在职认证  发表于 2018-4-21 13:23:26 |只看作者 |坛友微信交流群
hshly 发表于 2018-4-19 23:06
(?=\D+)或者(?
(?<=...)
Matches if the current position in the string is preceded by a match for ... that ends at the current position. This is called a positive lookbehind assertion. (?<=abc)def will find a match in 'abcdef', since the lookbehind will back up 3 characters and check if the contained pattern matches. The contained pattern must only match strings of some fixed length, meaning that abc or a|b are allowed, but a* and a{3,4} are not. Note that patterns which start with positive lookbehind assertions will not match at the beginning of the string being searched; you will most likely want to use the search() function rather than the match() function:

>>>
>>> import re
>>> m = re.search('(?<=abc)def', 'abcdef')
>>> m.group(0)
'def'
This example looks for a word following a hyphen:

>>>
>>> m = re.search(r'(?<=-)\w+', 'spam-egg')
>>> m.group(0)
'egg'


(?=...)
Matches if ... matches next, but doesn’t consume any of the string. This is called a lookahead assertion. For example, Isaac (?=Asimov) will match 'Isaac ' only if it’s followed by 'Asimov'.
已有 1 人评分热心指数 收起 理由
hshly + 5 精彩帖子

总评分: 热心指数 + 5   查看全部评分

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-30 23:35