Re: [pcre-dev] named pattern question

Top Page
Delete this message
Author: ph10
Date:  
To: Ze'ev Atlas
CC: Pcre Exim
Subject: Re: [pcre-dev] named pattern question
On Sun, 5 Feb 2017, Ze'ev Atlas wrote:

> On the testinput2 file, there is a pattern/(?<n>a|b|c)\g<n>*/
> Trying the same pattern in Perl (5.20 on Windows) generates the
> error Unterminated \g... pattern in regex; marked by <-- HERE in
> m/(?<n>a|b|c)\g <-- HERE <n>*/ at perltst.pl line 14.
>
> I am not clear whether the pattern is universally legitimate or is it
> legitimate only in the context of PCRE2.  I (and would) upgrade my
> Perl, but could you please shed some light Thank you  Ze'ev Atlas


Here is the light, taken from the pcre2pattern.3 man page:

"Absolute and relative subroutine calls"

For compatibility with Oniguruma, the non-Perl syntax \g followed by a
name or a number enclosed either in angle brackets or single quotes,
is an alternative syntax for referencing a subpattern as a
"subroutine". Details are discussed later. Note that \g{...} (Perl
syntax) and \g<...> (Oniguruma syntax) are *not* synonymous. The
former is a back reference; the latter is a subroutine call.

In other words, it's a PCRE2 (and also PCRE1) thing.

Philip

--
Philip Hazel