Operating System - HP-UX
1828322 Members
3832 Online
109976 Solutions
New Discussion

character classes in regular expressions

 
SOLVED
Go to solution
Jdamian
Respected Contributor

character classes in regular expressions

Character classes aren't recognized by grep(1) and awk(1). For instance, the following command line displays nothing:

echo "eeee" | grep -E '[:alpha:]'
Is there any mistake in it ?
3 REPLIES 3
Jean-Louis Phelix
Honored Contributor
Solution

Re: character classes in regular expressions

Hi,

It works this way with tr. But I think that with grep you should use :

echo "eeee" | grep -E '[[:alpha:]]'

to specify a class.

Regards,

Jean-Louis.
It works for me (© Bill McNAMARA ...)
H.Merijn Brand (procura
Honored Contributor

Re: character classes in regular expressions

Jean-Louis is right.

grep -E is shorter available as egrep

Jeffrey Friedl has an extensive comparison available in Chapter 6 of his book "Mastering Regular Expressions" 1st ed. The second edition I do not have here at work right now, so I cannot check which chapter it in.

It compares regular expression usage for traditional grep, vi, modern grep, modern sed, egrep, lex, trditional awk, GNU emacs, perl, tcl, default python, and expect

For grep and awk it has two seperate tables to just show the differences between the different versions of grep and awk.

FWIW {:...:] are POSIX character classes. Perl-5.8.0 uses \w for words [A-Za-z0-9_], which automagically includes the `letters' from the current locale
Enjoy, Have FUN! H.Merijn
Jdamian
Respected Contributor

Re: character classes in regular expressions

Thanx a lot everyone.

I read man pages but these tricks cannot be found.