Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: regex search for words with one digit

by haj (Vicar)
on Sep 21, 2020 at 16:08 UTC ( [id://11122009]=note: print w/replies, xml ) Need Help??


in reply to regex search for words with one digit

Digits are, in Perl regular expressions, word characters.

If you want to exclude digits, you can use character classes: Either those defined by POSIX (only if you don't have Unicode characters), or using Unicode properties in a recent Perl.

Here's a Unicode-aware example:

use strict; use warnings; my $text = "John P5ete Andrew Richard58 Nic4k Le7on5"; my @names = $text =~ /\b\p{Alphabetic}*\d\p{Alphabetic}*\b/g; print "@names\n";

Replies are listed 'Best First'.
Re^2: regex search for words with one digit
by AnomalousMonk (Archbishop) on Sep 21, 2020 at 18:27 UTC
    /\b\p{Alphabetic}*\d\p{Alphabetic}*\b/

    Note that this matches the name '1'.


    Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11122009]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found