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

Re: autodetecting MBR location

* Bart Schuller 

| 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 
| > 
| > s/[0-9]$//
| > 
| > 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.

Not on my box:
$perl -e '$_ = "/dev/hda5" ; s/[0-9]*//; print '; echo
$perl -V
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:

It will match the zero-width string between ^ and the first slash.
Leftmost is preferred over longer strings, unless you are using a
POSIX regex engine, where you are required to match the longest

| 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".

No, it is classified as 'match a zero width string' which is a
perfectly acceptable match and a very much different thing than a


Tollef Fog Heen
Unix _IS_ user friendly... It's just selective about who its friends are.

Reply to: