On 10/23/21 17:37, Bruce Gray wrote:
On Oct 23, 2021, at 6:43 PM, ToddAndMargo via perl6-users <[email protected]> wrote: Hi All, Wish I had a Q[;;;] expression inside a regex, but I don't This is my notes on how to do a regex with a special characters in it: Regex with literals in it: $JsonAddr ~~ s| (';') .* ||; It "usually" works. Unfortunately this one hangs my program (I am slicing up a web page): $NewRev ~~ s/ .*? ('Release Notes <strong>V') //; I need a better way of doing the above. Many thanks, -TJust anchor the start of the pattern, using `^` : $NewRev ~~ s/ ^ .*? ('Release Notes <strong>V') //; In the code below: * Target_V is matched by the original pattern, at high speed. * Target_V is matched by the anchored pattern, at high speed. * Target_Z hangs the original pattern. * Target_Z is correctly fails at match the anchored pattern, at high speed. my $target_V = 'Release Notes <strong>V'; # Will match pattern(s) below my $target_Z = 'Release Notes <strong>Z'; # Will not match pattern(s) below # Uncomment one of these two lines: my $target = $target_V; # my $target = $target_Z; # Simulate a big HTML page: my $NewRev = ('abcdefghijklmnopqrstuvwxyz' x 100) ~ $target ~ ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' x 100) ~ $target ~ ('12345678901234567890123456' x 100); # Uncomment one of these two lines: $NewRev ~~ s/ .*? ('Release Notes <strong>V') //; # Original # $NewRev ~~ s/ ^ .*? ('Release Notes <strong>V') //; # Anchored
Hi Bruce, I did fix the hang. I was accidentally feeding the regex a nul string. I am not understanding what you mean by "anchor" -T
