in reply to Re: How do I determine if a string contains non ascii characters
in thread How do I determine if a string contains non ascii characters

Thanks. I couldn't think of any other sensible way of doing it but I wanted to make sure I wasn't missing anything obvious.
It would have been nice if there was already a pre-defined character class for this though.(since \A and \a are already taken so I suppose \I and \i?)
  • Comment on Re: Re: How do I determine if a string contains non ascii characters

Replies are listed 'Best First'.
Re: Re: Re: How do I determine if a string contains non ascii characters
by japhy (Canon) on Jul 13, 2001 at 16:08 UTC
    There is a POSIX macro for this: [:ascii:]. That is NOT a character class in and of itself -- it must be used IN a character class:
    if ($string =~ /[^[:ascii:]]/) { # a non-ASCII character was found! }


    japhy -- Perl and Regex Hacker

      Or use the negated POSIX (perlish addition) 'character class' directly: if ($string =~ /[[:^ascii:]]//) {

      -- Hofmator