Re: autodetecting MBR location
Bart Schuller <firstname.lastname@example.org> wrote:
>On Tue, Jan 02, 2001 at 02:24:22PM +0100, Tollef Fog Heen wrote:
>> | s/[0-9]*//
>> | s/part$/disc/
>> What is the use of the first s/? Unless your first letter is a digit,
>> it will just remove the zero-width string '' between the first / and
>> the beginning of the string.
>> A better solution will probably be to
>> which will remove 5 from /dev/hda5.
>You seem to know that $ and ^ anchor a match to the end or the beginning
>of a string. So you should also know that in the absence of one of
>these characters, the match may start anywhere in the string. So the
>statement works fine as it is.
That's not true; try it.
[cjw44@riva ~]$ echo /dev/hda1 | perl -pe 's/[0-9]*//'
[cjw44@riva ~]$ echo /dev/hda1 | perl -pe 's/[0-9]+//'
Contrary to the subconscious assumption many people make, the first
priority for a regex is to match earliest, not to match longest.
regex(7) specifically mentions this:
In the event that an RE could match more than one sub-
string of a given string, the RE matches the one starting
earliest in the string. If the RE could match more than
one substring starting at that point, it matches the
>However, stylistically s/[0-9]*// is better written as s/[0-9]+//
>because the case where no digits match is better classified as
>"not a match".
True; even s/\d+// or s/\d+$// (assuming that the partition numbers are
always at the end, even in devfs - I'm not familiar with that).
Colin Watson [email@example.com]