?

Log in

No account? Create an account
entries friends calendar profile adric.net Previous Previous Next Next
RegEx Drain Brammage - nil.enroll(aetheric_username, quantum_class_id)
yljatlhQo'! QIch lo'laltbebej!
adric
adric
RegEx Drain Brammage
Whats this do? ^([^.?]+)$ Or rather, how does it do it, and why wouldn't something simpler work, like ^(.+)$ ?

in:
RewriteEngine on
# Rewrite /foo/bar to /foo/bar.php
RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]
# Return 404 if original request is /foo/bar.php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteRule .* - [L,R=404]
from: http://us2.php.net/manual/en/security.hiding.php#72630


From beginning of line (^) to end of line ($) match () one-or-more (+) of ... not-character followed by a question mark ?? ... or perhaps zero-or-more not-characters ?

Tags: ,
Current Location: NOC

2 comments or Leave a comment
Comments
gladstone From: gladstone Date: October 4th, 2007 03:32 am (UTC) (Link)
I'm probably wrong because I have never studied regular expressions.

A dot inside square brackets is literal, so [.] matches a dot. Therefore, [.?] matches either one or zero dots, and [^.?] would match anything other than one or zero dots (i.e. any non-dot non-null character). Thus ^([^.?]+)$ would match one or more non-dot non-null characters. ^(.+)$ would match a string of dots, and ^([^.]+)$ would almost work, matching any string consisting of non-dot characters, but it would also match the null set.

Make sure and point out my errors. I like to learn.
gladstone From: gladstone Date: October 4th, 2007 04:07 am (UTC) (Link)
Or perhaps, since [^.] would match a single non-dot character, [^.?] would match zero or one non-dot characters and ^([^.?]+)$ would a line of zero or more characters, provided it did not contain a dot, and ^([^.]+)$ would match a string of one or more non-dot characters, but would not match an empty string. This stuff is kinda tricky, huh?
2 comments or Leave a comment