Leon wrote:
> 
> ...
> > \b stands for a word boundary and has a length of 0.
> 
> (4) Is this boundary \b equivalent to an empty string? What is the meaning
> of 0 length? Is 0 lenght = empty string?

No. Imagine how a regexp machine works.
Simplified there is a pointer which directs to the characters of the
given string.
Exactly it directs between the chars.
If there is a "normal" char to match, 
let's say \w the regexp machine looks to the char right of it's pointer.
If it is a \w it goes to the gap right of it's right neighboured
pointer.

But there can be also something in the gap.
One example for is \b. Another is \A or \Z (begin or end of whole the
string)
You can imagine the sentence "Upgrade Windows to Linux" as
    U p g r a d e     W i n d o w s     t o     L i n u x
\A\b             \b \b             \b \b   \b \b         \b\Z.

These special characters have all length 0.
That means, the regexp machine looks at the current gap,
whether the special character is there.
If so, the machine doesn't go right.
It stand there where it is.

Length of 0 of something means, 
that regexp try to match the something,
but doesn't go to right.

There exists the important positve or negative look aheads or behinds,
which have length 0, too.
E.g. /(\d\d)(?!\d)/g finds all numbers from 10-99 in a text.
It's not equivalent to /(\d\d)\D/g.
Look simply to "99". It can't match /(\d\d)\D/g, 
because there are less than 3 characters total.
Instead (?!\d) just looks, that no digit follows.
It doesn't matter whether there's an other character.

> 
> > In $key there are two word boundary,
> > before the 1 and after the 4.
> 
> (5)  Therefore are you saying that $key is equivalent to \b1234\b and when
> match with an empty string, obviously they matched. Have I read you
> correctly?
> Hmmmm ! very interesting.
> 

Let's clarify. $key = "1234" can be seen as equivalent to \b1234\b.
But be careful with this expressen.
$key = "\b1234\b" is possible, too.
But it has a total different meaning.
In strings \b stands for the backspace.
Better to say, $key = "1234" MATCHES \b1234\b.

>From this point of view, it's clear,
that $key = "1234" MATCHES nothing too.
(of course, in "1234" is a lot in, nothing too).
Exactly it would matches the nothing before the 1 :-)

But $nothing = '' doesn't match /\b\b/,
because there aren't any word boundaries in.

> (6)  So what must I do so that $key match something but not an empty
> value/string?

Use a regexp like 
/[.\n]/ 
/./s
/\A(?!\Z)/s


Please excuse my bad explications.
You can find better explications in the Camel book or
in "Mastering Regular Expressions" by Jeffrey Friedl (O'Reilly).

Best Wishes,
Happy Xmas,
Andrea

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to