-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Dmitry Dobrushin on 11/15/2008 11:41 AM:

Hello Dmitry,

Thanks for the report; however, this is not a bug.

> command:
> expr match "ut96_01_200" "\([0-9][0-9]_[0-9][0-9]\)"
> 
> did not return,

It returned, it just gave the (correct) answer of an empty string.  expr
implicitly anchors its regexp at the start of the string, and 'u' does not
match [0-9].

> while another command:
> 
> expr match "ut96_01_200" ".*\([0-9][0-9]_[0-9][0-9]\)"
> 
> return : "01_20"

Regular expressions are greedy - if more than one candidate matches the
pattern (in your case, both ut96_01 and ut96_01_20), then the longest
match is chosen.

> 
> What should I do to get the desired "96_01" result?

Depends on what pattern you will be matching against (in other words, I
don't know what format of strings you are trying to match - are they
always two letters followed by your desired pattern?).  But for this
particular example, you could use:

expr match "ut96_01_200" "[^0-9]*\([0-9][0-9]_[0-9][0-9]\)"

Or, to be more portable to POSIX (since 'match' is an extension), you
should use the colon operator:

expr "ut96_01_200" : "[^0-9]*\([0-9][0-9]_[0-9][0-9]\)"

- --
Don't work too hard, make some time for fun as well!

Eric Blake             [EMAIL PROTECTED]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkkfJ/EACgkQ84KuGfSFAYDkvgCgop78aVS4L4dcqnLX/n0DdFW8
or8An1bCkEG0478O6DgqARPLPsouPLDL
=n4vp
-----END PGP SIGNATURE-----


_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to