正则表达式替换混合数字+字符串

pro*_*ype 3 php python regex

我想删除包含数字的所有单词,示例:

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)

Tim*_*ker 6

是的你可以:

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)