bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'expr' and weird character classes


From: Andreas Schwab
Subject: Re: 'expr' and weird character classes
Date: Mon, 10 May 2004 11:53:40 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3.50 (gnu/linux)

DervishD <address@hidden> writes:

>     Hello all :)
>
>     I'm using coreutils 5.2.1 and I've noticed a weird behaviour of
> 'expr'. I don't know if it's my fault, but a command like:
>
>     $ expr "x" : "[:alpha:]"

This matches "x" against the set of characters ":ahlp".

>     returns 0 instead of 1, but a command like:
>
>     $ expr "x" : "[[:alpha:]]"

This matches "x" against the set of characters from the character class
"alpha".

>     returns 1, correctly. That is, 'expr' understands character
> classes but it needs that double bracket :(

The syntax of a character class is [:CLASS:], _including_ the brackets.
Thus to build a regular expression that matches a single lower case letter
or digit or underscore, you write "[[:lower:][:digit:]_]".

> This is non portable AFAIK, at least is not SUSv3 compliant regarding
> basic regular expressions

Please read again.

> and other binaries like 'tr'

`tr' doesn't expect regular expressions as arguments, but rather they are
interpreted as character sets without the surrounding brackets.

>     Am I doing something wrong?

You are mixing the syntax for a regular expression containing a character
set with the syntax for a character class inside a character set.

Andreas.

-- 
Andreas Schwab, SuSE Labs, address@hidden
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




reply via email to

[Prev in Thread] Current Thread [Next in Thread]