【问题标题】:Multiline string not captured by regex [duplicate]正则表达式未捕获多行字符串[重复]
【发布时间】:2019-09-02 17:41:09
【问题描述】:

将正则表达式应用于多行字符串时,我意识到根据 rubular.com,正则表达式可能是正确的。问题是它在某种程度上不适用于多行文本。问题是,我尝试做“item.strip()”并且行为没有改变。

s = """ #if route rate 230.207.200.1', '', '   
(50.50.50.11,230.207.200.1)', """
for item in s: 
    match = re.findall(r'([0-9].[0-9].[0-9].[0-9],.........)', s) 
if match:
    print('match')

【问题讨论】:

  • 可能大多数正则表达式工具都需要一些选项来处理多行。

标签: python regex multiline


【解决方案1】:

你那里有任何行尾匹配或点字符吗? 尝试将标志设置为re.DOTALLre.MULTILINE,例如:

re.findall(r'...', s, flags=re.DOTALL)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    • 2020-07-12
    • 2020-08-08
    • 1970-01-01
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    相关资源
    最近更新 更多