简体   繁体   English

在Python MULTILINE模式下仅匹配字符串的开头

[英]Matching only the beginning of a string in Python MULTILINE mode

Python's re module says this: Python的re模块说:

'^'

(Caret.) Matches the start of the string, and in MULTILINE mode also matches immediately after each newline. (Caret。)匹配字符串的开头,并且在MULTILINE模式下,每个换行符之后也立即匹配。

I want to use MULTILINE but I want to require a match at the beginning of the string (not just the beginning of a line). 我想使用MULTILINE,但是我想在字符串的开头(而不只是行的开头)要求匹配。 Is there a way to do this? 有没有办法做到这一点?

Just use the \\A anchor that matches the start of string unambiguously. 只需使用\\A明确匹配字符串开头的锚即可。

Check the Regular Expression Syntax : 检查正则表达式语法

\\A \\一种
Matches only at the start of the string. 仅在字符串开头匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM