Forum Moderators: phranque

Message Too Old, No Replies

code interpretation

         

smallcompany

10:18 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi,

The two lines are both aimed to rewrite all HTML to PHP (one or another):

^(.*)\.html$ $1.php

([^.]+)\.html$ /$1.php

What would be the difference between them? What is

^(.*) vs. ([^.]+)

and

$1.php vs. /$1.php

Answers to such questions seem to be hard to find on reference sites.

Thanks :)

jdMorgan

10:27 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Regular expressions:

.* "Match any number of any characters -- including zero"

[^.]+ "Match one or more characters except a literal period" -- or equivalently, "Match one or more characters until you find a period."

In the first pattern, everything in the string is initially matched into the pattern, leaving nothing for the rest of the pattern (in your example, "\.html") to match. Therefore, the matching engine will have to make multiple passes to make a match, backing off one character at a time through l, m, t, h, and the period.

Therefore, the second pattern is more efficient, because it is much less ambiguous.

Take a look in our forum charter (link at top left) for some useful links.

Jim