给定一个字符串#abcde#jfdkjfd
,我如何获得两个字符串之间的字符串#
?我也希望如果没有#
对(意味着没有#
或只有一对#
),函数将返回None
.
>>> import re
>>> s = "abc#def#ghi#jkl"
>>> re.findall(r"(?<=#)[^#]+(?=#)", s)
['def', 'ghi']
Run Code Online (Sandbox Code Playgroud)
说明:
(?<=#) # Assert that the previous character is a #
[^#]+ # Match 1 or more non-# characters
(?=#) # Assert that the next character is a #
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3019 次 |
最近记录: |