Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

printable characters

17 views
Skip to first unread message

George Mpouras

unread,
May 23, 2012, 6:35:17 AM5/23/12
to
I have the regex

my $regex = qr/^([\w `^~!@;:,+%&|<>{}()=\-\$\*\?\[\]\\\.\/\'"#]*)$/;

for matching the printable characters `^~!@#$%&*?_+-={}[]()<>;:'"|\,./
a..z A..Z 0..9
is there any better approach ?


Jim Gibson

unread,
May 23, 2012, 3:35:04 PM5/23/12
to
In article <jpieg9$1io0$1...@news.ntua.gr>, George Mpouras
You can try the Posix character classes [[:print]], which includes
"printable" whitespace, and [[:graph:]], which does not.

See 'perldoc perlrecharclass' for other forms.

--
Jim Gibson

Jürgen Exner

unread,
May 24, 2012, 11:48:59 PM5/24/12
to
"George Mpouras" <nospam.gr...@hotmail.com.nospam> wrote:
>I have the regex
>
>my $regex = qr/^([\w `^~!@;:,+%&|<>{}()=\-\$\*\?\[\]\\\.\/\'"#]*)$/;
>
>for matching the printable characters `^~!@#$%&*?_+-={}[]()<>;:'"|\,./
>a..z A..Z 0..9

Luckily you are mistaken because depending on your locale \w will match
much more than just those limited ASCII characters .

>is there any better approach ?

Use the class [[:print:]]

Oh, and no, you don't need modules for this.

jue
0 new messages