【问题标题】:Python REGEX ignore case at the beginning of the sentence and take the restPython REGEX 忽略句子开头的大小写并取其余部分
【发布时间】:2016-09-22 14:27:24
【问题描述】:

我有这样的结果:

ª!è[008:58:049]HTTP_CLI:0 - Line written in...

我想忽略所有开头的字符,如ª!è,只得到:HTTP_CLI:0 - Line written in...,但在一个简单的正则表达式行中。

我试过这个:^[\W0-9]*,但正在使用扩展的 ASCII 字符加上时间并且没有忽略它,正在做相反的事情......

有什么帮助吗?

谢谢!

【问题讨论】:

  • 你是怎么尝试的? (给我们看一些代码..)
  • 使用re.sub(r'^[^a-zA-Z]+', '', s)。
  • 我试过这个:^[^\W0-9]*HTTP_CLI:0 - Linewritten.*
  • re.search("(?<=\]).*",tester).group(0);其中tester = ª!è[008:58:049]HTTP_CLI:0 - Line written in....

标签: python regex ignore-case


【解决方案1】:

如果您想获取右方括号之后的所有内容,无论如何,并跳过之前的所有内容,您可以使用match,如下所示:

s = "ª!è[008:58:049]HTTP_CLI:0 - Line written in..."
m = re.match(r'^.*?]([\S\s]*)', s)
print(m.group(1))

打印的'HTTP_CLI:0 - Line written in...'

此表达式在右括号之前查看任意数量的字符,并匹配之后的所有字符。匹配组可用m.group(1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-23
    • 2010-10-31
    • 2021-06-01
    • 2010-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多