Selecting all printable characters (regex)

J

Joe Christl

Hey all,

Is there an easier way to specify all printable characters instead of:

[-\]\\!@#$%^&*()_=+./?|[{};:'"~`\w\s]

Joe
 
J

Josef Moellers

Joe said:
Hey all,

Is there an easier way to specify all printable characters instead of:

[-\]\\!@#$%^&*()_=+./?|[{};:'"~`\w\s]

I bet that someone will disagree that this class includes all printable
characters B-{)

Better use \p{IsPrint}

Josef
 
P

Paul Lalli

Joe said:
Hey all,

Is there an easier way to specify all printable characters instead of:

[-\]\\!@#$%^&*()_=+./?|[{};:'"~`\w\s]

Those are *all* printable characters?

How about , < > ?
How about á é í ó ú Á É Í Ó Ú ä ë ï ü ö Ä Ë Ï Ö Ü
å Å ?
How about ñ Ñ æ Æ µ ç Ç ¿ ¡ ?
How about © ß ð ¢ § « » ø Ø ?

You have an odd definition of "all"...

Paul Lalli

P.S. There are others I didn't bother typing, too...

P.P.S \w will match many of those characters I gave, *IF* use locale;
is in effect and the locale respects those characters as "word"
characters.
 
P

Pradeep

Hi,

The best thing is "." character in regex. It includes all the
characters except a newline character.

Regards,
Pradeep

Paul said:
Joe said:
Hey all,

Is there an easier way to specify all printable characters instead of:

[-\]\\!@#$%^&*()_=+./?|[{};:'"~`\w\s]

Those are *all* printable characters?

How about , < > ?
How about á é í ó ú Á É Í Ó Ú ä ë ï ü ö ÄË Ï Ö Ü
å Å ?
How about ñ Ñ æ Æ µ ç Ç ¿ ¡ ?
How about © ß ð ¢ § « » ø Ø ?

You have an odd definition of "all"...

Paul Lalli

P.S. There are others I didn't bother typing, too...

P.P.S \w will match many of those characters I gave, *IF* use locale;
is in effect and the locale respects those characters as "word"
characters.
 
R

Ralf Muschall

Joe said:
Is there an easier way to specify all printable characters instead of:

[-\]\\!@#$%^&*()_=+./?|[{};:'"~`\w\s]

What about [[:print:]]?

Ralf
 
P

Paul Lalli

Pradeep said:
Joe said:
Hey all,

Is there an easier way to specify all printable characters instead of:

[-\]\\!@#$%^&*()_=+./?|[{};:'"~`\w\s]
The best thing is "." character in regex. It includes all the
characters except a newline character.

"Most inclusive" does not equate to "best". The OP asked for all
*printable* characters. As you said, . matches *all* characters
(including the newline if the /s modifier is used):

$_ = "\x00";
print "Any\n" if /./;
print "Printable\n" if /[[:print:]]/;
__END__
Any


Paul Lalli
 
T

Tad McClellan

[ top-posting (a sure sign of suspect content) repaired. ]


Pradeep said:
^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^

The best thing is "." character in regex. It includes all the
characters except a newline character.


Do you get paid for writing code to specification? (it appears not...)
 
A

axel

Joe Christl said:
Is there an easier way to specify all printable characters instead of:
[-\]\\!@#$%^&*()_=+./?|[{};:'"~`\w\s]

[ -~]

Seems to cover the Ascii character set pretty well. You could always add
\t to it is you wish to consider that a printable character:

[ -~\t]

Likewise \w if you are using a specific locale and wosh to include
letters beyond the basic Ascii set.

Axel
 
J

Jürgen Exner

Tad said:
Do you get paid for writing code to specification? (it appears not...)

Well, this 'spec' is incomplete. In particular it doesn't state what should
happen to non-printable characters.
Therefore, strictly speaking, the '.' is the perfect solution. It does match
all printable characters as requested by the spec. It also happens to match
all other characters, but that's not a problem because the spec didn't state
anything about those.

Now, I have to admit that in real live there won't be many customers or
bosses, who would agree with this view.

SCNR

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top