<img[\s]+(.*)>

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

nwp
Forum Contributor
Posts: 105
Joined: Sun Feb 04, 2007 12:25 pm

Post 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 ??
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post 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 ;)
nwp
Forum Contributor
Posts: 105
Joined: Sun Feb 04, 2007 12:25 pm

Post by nwp »

And now how the problem is solved using the $ sign ??
whats the job of the $ sign ??
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

Post Reply