control character in regex?

K

Ken Williams

I have a simple regex [A-Z0-9]. This hits all uppercase characters and
numbers. I also want all control characters to be in there. anyone know
how?

[A-Z0-9\c]

is that it?
 
J

John W. Krahn

Ken said:
I have a simple regex [A-Z0-9]. This hits all uppercase characters and
numbers. I also want all control characters to be in there. anyone know
how?

[[:upper:][:digit:][:cntrl:]]


John
 
B

Brian McCauley

John said:
Ken said:
I have a simple regex [A-Z0-9]. This hits all uppercase characters and
numbers. I also want all control characters to be in there. anyone know
how?

[[:upper:][:digit:][:cntrl:]]

That's quite possibly the most readable form, but it is worth beng
aware that Perl supports a number of notations for character classes
and you can mix and match them at will.

For example if bervity is your bag:

[A-Z\d\pC]

Note also tha A-Z can only be considered equivalent to [:upper:] and
\pC equivalent to [:cntrl:] when working with ASCII strings. [:upper:]
also includes a lot of other characters outside the ASCII range. \pC
also includes "PrivateUse" and "Unassigned" which AFAIK are not in
[:cntrl:].

When working with ASCII you could choose to represent controls as any
of the following

[\x00-\x1f\x7f]
\p{Cc}
\pC
\p{Control}
\p{IsCntrl}
[[:cntrl:]]
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top