Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PCRE: ^|$ and \A|\Z?

In PCRE, what's the difference between:

  • ^ and \A, and
  • $ and \Z?

I remember reading there was a subtle difference, but can't recall exactly what it was.

like image 978
Alix Axel Avatar asked Aug 07 '11 03:08

Alix Axel


People also ask

What is PCRE matching?

PCRE tries to match Perl syntax and semantics as closely as it can. PCRE also supports some alternative regular expression syntax (which does not conflict with the Perl syntax) in order to provide some compatibility with regular expressions in Python, . NET, and Oniguruma.

What is P in PCRE?

Perl Compatible Regular Expressions (PCRE) is a library written in C, which implements a regular expression engine, inspired by the capabilities of the Perl programming language.

What does (?: Mean in regex?

(?:...) A non-capturing version of regular parentheses. Matches whatever regular expression is inside the parentheses, but the substring matched by the group cannot be retrieved after performing a match or referenced later in the pattern.

How do you match in regex?

To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).


1 Answers

By default, there is no difference between the two, they both signify the start or end of the string. If, however, you use the m modifier, then ^ and $ will match the start and end of lines, respectively.

like image 134
EdoDodo Avatar answered Oct 28 '22 16:10

EdoDodo