Reputation: 10607
By control key here I mean the control key on the keyboard plus any letter. I can match them individually, by e.g. \cn or \cx, but how can I match all such keys?
Upvotes: 0
Views: 185
Reputation: 126742
The POSIX character class /[[:cntrl:]]/
is what you want.
It matches character codes 0 .. 0x1F and DEL (0xFF)
Upvotes: 1
Reputation: 887
You can match against a character class, i.e.
perl -lne 'print m/[[:cntrl:]]/?"yes":"no"'
Upvotes: 2
Reputation: 118665
Do you mean match in a regular expression? You can use a ranged character class:
$contains_ctrl_char = $_ =~ /[\c@-\c_]/;
$contains_ctrl_char = $_ =~ /[\000-\037]/;
$contains_ctrl_char = $_ =~ /[\x{00}-\x{1F}]/;
There's probably an appropriate POSIX character class for this, too, though I don't know what it is off hand.
Upvotes: 2