2011-09-20 90 views
2

之間有什麼區別,

\A Match at only beginning of string 
\Z Match at only end of string (or before newline at the end) 

^ Match the beginning of the line 
$ Match the end of the line (or before newline at the end) 
+2

用什麼語言?我在're_format(7)'手冊中看不到'\ A'或'\ Z'。 – Kusalananda

+0

你當然是對的。我最初的疑問是在Python中,但它適用於任何具有實現Perl Compatible Regular Expressions的模塊的語言(儘管Python .re沒有完全實現它) –

回答

4

從Perl文檔(我看不到他們的標準正則表達式語法):

「\ A」和「\ Z」與「^」和「$」類似,除了在使用「/ m」修飾符時不會匹配多次,而「^」和「$」將在每條內線邊界處匹配。

如果這隻與Perl(或使用PCRE和Perl兼容的正則表達式的語言或庫)相關,您應該添加一個perl標記。

+0

謝謝。 Upvoted並添加一個PCRE標籤 –