Page 2 of 2

Posted: Tue May 15, 2007 1:35 pm
by nwp
the $ sign is for what ??
EDIT
--------------------------------------------------
I see
/(.*?)(\W+?)(\1$)/ Matches only str@str not str@st not str@stry
But
/(.*?)(\W+?)(\1)/ Matches str@stry But shows
Array
(
[0] => str@str
[1] => str
[2] => @
[3] => str
)
It also matches str@st But shows
Array
(
[0] => @
[1] =>
[2] => @
[3] =>
)
So why here is the Difference due to the '$' Sign ??

Posted: Tue May 15, 2007 2:10 pm
by stereofrog
This is how pcre matches "ab@a" against /(.*?)(\W+?)(\1)/

Code: Select all

start from 'a'
match "ab" against (.*) - ok
match "@" against (\W+) - ok
match "a" against \1 (which is "ab") - FAILURE
backtrack

start from 'a'
match "a" against (.*) - ok
match "b" against (\W+) - FAILURE
backtrack

~10 steps omitted for brevity

start from '@'
match "" (nothing) against (.*) - ok, because * means "0 or more"
match @ against (\W+) - ok
match "" (nothing) against \1 (which is nothing) - ok

result is 
(.*) is nothing
(\W+) is @
hope this helps ;)

Posted: Tue May 15, 2007 11:08 pm
by nwp
And now how the problem is solved using the $ sign ??
whats the job of the $ sign ??

Posted: Wed May 16, 2007 1:36 am
by stereofrog