control character in regex?

Discussion in 'Perl Misc' started by Ken Williams, Mar 12, 2006.

  1. Ken Williams

    Ken Williams Guest

    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?
    Ken Williams, Mar 12, 2006
    #1
    1. Advertising

  2. Ken Williams wrote:
    > 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
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Mar 12, 2006
    #2
    1. Advertising

  3. John W. Krahn wrote:
    > Ken Williams wrote:
    > > 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:]]
    Brian McCauley, Mar 12, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Velvet
    Replies:
    9
    Views:
    14,780
    Joerg Jooss
    Jan 19, 2006
  2. raavi
    Replies:
    2
    Views:
    901
    raavi
    Mar 2, 2006
  3. Replies:
    3
    Views:
    735
    Reedick, Andrew
    Jul 1, 2008
  4. Bart Vandewoestyne
    Replies:
    8
    Views:
    707
    Bart Vandewoestyne
    Sep 25, 2012
  5. Sebastian
    Replies:
    17
    Views:
    345
    Gene Wirchenko
    Feb 4, 2013
Loading...

Share This Page