我想删除包含数字的所有单词,示例:
LW23 London W98 String
Run Code Online (Sandbox Code Playgroud)
从上面的字符串我唯一想要保留的是"London String".这可以用正则表达式来完成.
我目前正在使用Python,但PHP代码也很好.
谢谢!
编辑:
以下是我现在可以做的事情:
>>> a = "LW23 London W98 String"
>>> b = a.split(' ')
>>> a
['LW23', 'London', 'W98', 'String']
Run Code Online (Sandbox Code Playgroud)
是的你可以:
result = re.sub(
r"""(?x) # verbose regex
\b # Start of word
(?= # Look ahead to ensure that this word contains...
\w* # (after any number of alphanumeric characters)
\d # ...at least one digit.
) # End of lookahead
\w+ # Match the alphanumeric word
\s* # Match any following whitespace""",
"", subject)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1069 次 |
| 最近记录: |