in reply to Re^3: regex search for words with one digit (updated)
in thread regex search for words with one digit
Once you add in the restriction of "only one digit", the \b is required.
My
my $text = "John P5ete Andrew Richard58 Nic4k Le7on5"; my @names = $text =~ /\b[^\W\d]*\d[^\W\d]*\b/g; print "@names\n";
outputs
P5ete Nic4k
but without the \b's
my $text = "John P5ete Andrew Richard58 Nic4k Le7on5"; my @names = $text =~ /[^\W\d]*\d[^\W\d]*/g; print "@names\n";
it outputs
P5ete Richard5 8 Nic4k Le7on 5
It's pulling patterns out of the middle of "words".
In Section
Seekers of Perl Wisdom