Home How does \G work in PCRE lookbehinds
Reply: 0

How does \G work in PCRE lookbehinds

user781
1#
user781 Published in June 20, 2018, 10:42 pm

After reading though How does \G work in .split? I quickly set up a Delphi program to check how PCRE handles this case. Interestingly the results were not the same as in the java case:

program Project1;
{$APPTYPE CONSOLE}
uses
  System.RegularExpressions;
var
  SArr: TArray<string>;
  S: string;
begin
  SArr := TRegex.Split('abcdefghij', '(?<=\G..)',[]);
  for S in SArr do
  begin
    WriteLn(S);
  end;
  ReadLn;
end.

Outputs:

ab
cde
fgh
ij

Why does the PCRE result differ from the Java one? How is this behaviour to be explained?

To make sure this isn't an Delphi error, I tested in regex 101 and the matching behaviour seems to be the same: https://regex101.com/r/GE6eRI/1

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.253783 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO