python - How to match multiple strings with regular regularity instead of a single letter
怪我咯
怪我咯 2017-05-18 10:47:24
0
2
812

For example, in the following string, multiple repetitions of 'asd' are matched 'asdasdasdasdasdasdasdasd' instead of a single 'asd'
string='asdasdasdasdasdasdasddasfdhgasghsd'
Thank you!

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
洪涛
string = 'asdasdasdasdasdasdasddasfdhgasghsd'
print(re.findall(r'((?:asd)+)', string))

# 解释下
# (?:asd)+ 是正则的一种不存分组的语法, 它具有2个用途, 将`asd`看成一个样式整体, 所以当我们用+时, 就能代表多个asd
# () 最外层的括号就是将匹配的结果存入分组, 与上面不同的就是, 少了`?:`, 因为没有这个, 所以它能存到分组
# 所以整体的结果就是: 将多个asd匹配, 并存入分组, 然后在re.findall的结果就能看到了
为情所困

/asd/g

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template