Selecting all printable characters (regex)

Discussion in 'Perl Misc' started by Joe Christl, Aug 3, 2005.

  1. Joe Christl

    Joe Christl Guest

    Hey all,

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

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

    Joe
     
    Joe Christl, Aug 3, 2005
    #1
    1. Advertising

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


    [[:print:]]


    John
    --
    use Perl;
    program
    fulfillment
     
    John W. Krahn, Aug 3, 2005
    #2
    1. Advertising

  3. Joe Christl wrote:
    > 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
    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
     
    Josef Moellers, Aug 3, 2005
    #3
  4. Joe Christl

    Paul Lalli Guest

    Joe Christl wrote:
    > 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.
     
    Paul Lalli, Aug 3, 2005
    #4
  5. Joe Christl

    Pradeep Guest

    Hi,

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

    Regards,
    Pradeep

    Paul Lalli wrote:
    > Joe Christl wrote:
    > > 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.
     
    Pradeep, Aug 3, 2005
    #5
  6. Joe Christl

    Joe Christl Guest

    I thought the same thing, but hey... whatcha gonna do.
     
    Joe Christl, Aug 3, 2005
    #6
  7. Joe Christl wrote:
    > Is there an easier way to specify all printable characters instead of:
    >
    > [-\]\\!@#$%^&*()_=+./?|[{};:'"~`\w\s]


    What about [[:print:]]?

    Ralf
     
    Ralf Muschall, Aug 3, 2005
    #7
  8. Joe Christl

    Paul Lalli Guest

    Pradeep wrote:
    > > Joe Christl wrote:
    > > > 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
     
    Paul Lalli, Aug 3, 2005
    #8
  9. Joe Christl <> wrote:

    > I thought the same thing,



    The same thing as _what_?


    > but hey... whatcha gonna do.



    Quote some context in followups like everyone has been doing
    for the previous 25 years.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Aug 6, 2005
    #9
  10. [ top-posting (a sure sign of suspect content) repaired. ]


    Pradeep <> wrote:
    >> Joe Christl wrote:


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

    ^^^^^^^^^^^^^^^^^^^^^^^^
    ^^^^^^^^^^^^^^^^^^^^^^^^

    > 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...)


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Aug 6, 2005
    #10
  11. Joe Christl

    Guest

    Joe Christl <> wrote:
    > Hey all,


    > 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
     
    , Aug 6, 2005
    #11
  12. Tad McClellan wrote:
    > Pradeep <> wrote:
    >>> Joe Christl wrote:

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

    > ^^^^^^^^^^^^^^^^^^^^^^^^
    >
    >> 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...)


    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
     
    Jürgen Exner, Aug 6, 2005
    #12
    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. qazmlp
    Replies:
    2
    Views:
    415
    John Harrison
    Jul 23, 2003
  2. qazmlp
    Replies:
    0
    Views:
    401
    qazmlp
    Jul 23, 2003
  3. Pascal
    Replies:
    3
    Views:
    679
    Roel Mathys
    Dec 4, 2003
  4. Daniel Alexandre
    Replies:
    2
    Views:
    561
    Sibylle Koczian
    Mar 21, 2005
  5. Larry
    Replies:
    19
    Views:
    299
    comp.llang.perl.moderated
    Dec 25, 2007
Loading...

Share This Page