ctype / isprint ?

H

Hadmut Danisch

Hi,

what's the best way to check whether a String consists of printable
characters only? (In C: isprint from ctype)

Maybe would be nice to have the ctype classes as patterns in the
regular expressions.

regards
Hadmut
 
D

Daniel Brockman

Hi Hadmut,
what's the best way to check whether a String consists of
printable characters only? (In C: isprint from ctype)

Maybe would be nice to have the ctype classes as patterns
in the regular expressions.

It's your lucky day:

"a b c" =~ /\A[[:print:]]*\z/ #=> 0

"a \0 c" =~ /\A[[:print:]]*\z/ #=> nil
 
A

Ara.T.Howard

Hi Hadmut,
what's the best way to check whether a String consists of
printable characters only? (In C: isprint from ctype)

Maybe would be nice to have the ctype classes as patterns
in the regular expressions.

It's your lucky day:

"a b c" =~ /\A[[:print:]]*\z/ #=> 0

"a \0 c" =~ /\A[[:print:]]*\z/ #=> nil

is that locale senstive?

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| My religion is very simple. My religion is kindness.
| --Tenzin Gyatso
===============================================================================
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: ctype / isprint ?"

|> "a b c" =~ /\A[[:print:]]*\z/ #=> 0
|>
|> "a \0 c" =~ /\A[[:print:]]*\z/ #=> nil
|
|is that locale senstive?

1.8 regex uses C ctype macros, so that it is locale sensitive.
Oniguruma (1.9 regex engine) does not use locales. It uses encoding
information, since C locale model is just not suitable to handle
multiple encoding schemes in a program, like Oniguruma does.

matz.
 
H

Hadmut Danisch

Daniel said:
It's your lucky day:

"a b c" =~ /\A[[:print:]]*\z/ #=> 0

"a \0 c" =~ /\A[[:print:]]*\z/ #=> nil


Great, thanks.


(I should start to read the manual...)


Hadmut
 

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,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top