in reply to Re^4: Regex word boundries
in thread Regex word boundries
Non-capturing parens ((?:...)) are just like parens ((...)) in Perl code. The alter precedence.
# Matches strings that include "ab" or "cd" /ab|cd/ # Matches strings that include "abd" or "acd". /a(?:b|c)d/
(?=...) performs a match, but leaves pos unchanged after the match.
local $_ = 'foo bar bar baz'; my $term = 'bar'; my $num_matches = () = /(?:\W|^)\Q$term\E(?:\W|\z)/g; print("$num_matches\n"); # 1: foo[ bar ]bar baz my $num_matches = () = /(?:\W|^)\Q$term\E(?:(?=\W)|\z)/g; print("$num_matches\n"); # 2: foo[ bar][ bar] baz
|
|---|