今天我碰到这行代码:无法理解re.findall模式语法
re.findall(r"#[^:]+:([^#]+)", str)
我什么模式findall
功能正在寻找非常困惑。具体而言,r"#[^:]+:([^#]+)"
是什么意思?
我是一名高中生,所以如果你能用简单的话来解释它,那就太棒了!
今天我碰到这行代码:无法理解re.findall模式语法
re.findall(r"#[^:]+:([^#]+)", str)
我什么模式findall
功能正在寻找非常困惑。具体而言,r"#[^:]+:([^#]+)"
是什么意思?
我是一名高中生,所以如果你能用简单的话来解释它,那就太棒了!
它的意思是:
# => matches the character # literally (case sensitive) [^:] => Match a single character that is not : + => Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy) and is applied to the [^:] : => matches the character : literally (case sensitive) ([^#]+) => Capturing Group [^#] => Match a single character not present in this list (match anything other than #) + => Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy) and is applied to [^#]
并注意r
字面意思是所要引用的字符串是raw
文本,这意味着它里面什么没有任何特殊含义的编译器和你不必须逃避任何字符,甚至双引号!
您应该开始阅读[documentation](https://docs.python.org/2/library/re.html)并更新您的问题。 –
作为阅读文档的补充,您可以测试您的正则表达式并获得关于它如何与[regex101.com](https://regex101.com)一起使用的解释。 –
我应该如何更新它? – Joe