SUMMARY:why is the result of the regular expression in following command "rz14"

From: Willig Reimund <Willig.Reimund_at_gdr.de>
Date: Fri, 15 May 1998 12:58:21 +0200

Hallo regular expressionists!
its really great how fast this supportline solves problems. As the
solution for my question i simply copy two mails, which were very
helpfull (thank you!!):

1. from Sam Nelson [Sam.Nelson_at_cs.stir.ac.uk]

The '\(' and '\)' brackets mean `return this part when matched'. The
stuff
inside the bracket means `an arbitrary-length string of non-digit
characters'
(that's the `[^0-9]*' part) followed by `an arbitrary-length string of
digits'
(that's the `[0-9]*' part). It looks as if what's happening is that
someone
is trying to turn a partition name (`rz14c' or something like that) into
the
name of the device the partition comes from, because the part that
wouldn't
be returned would be the guff at the end (`.*') is just `an
arbitrary-length
string of characters'). If you give that regular expression "rz14c" as
an
input string, for example, it returns "rz14".

I must admit that I (perhaps paranoiacally) use single quotes around
regular
expressions to guard them from `early interpretation'.




2. from Per Boussard T/ED [Per.Boussard_at_era-t.ericsson.se]

Here's a try..

(Hint: Check what expr "rz14" : "\([^0-9]*\)[0-9]*.*" and
expr "rz14" : "[^0-9]*\([0-9]*\).*" and
expr "rz14" : "[^0-9]*[0-9]*\(.*\)" returns)

expr will return what is between \( and \).

the first [^0-9]* will match any number of characters that are *not*
digits (note the '^'), hence it matches 'rz'. The next one is [0-9]*,
which will match any number of digits (hence '14'). The .* matches any
number of characters (including an empty set, which is the case here).

Remember that expr implicitly anchors the expression (i.e. there's a ^
in
the beginning and an $ in the end of the expression implied).



mit freundlichen Grüßen
     Reimund Willig
 willig.reimund_at_gdr.de
Received on Fri May 15 1998 - 13:00:19 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:37 NZDT