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
In reply to Re^5: Regex word boundries
by ikegami
in thread Regex word boundries
by MonkPaul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |