blog.autopsy.se

basically; it sucks. everything sucks. but.. in a good way..

Perl 5.8.8 sucks, or the lack of Perl 5.10 on my box sucks! Really

Been struggling with a regexp using perl since I couldn't get sed to work as I wanted (mainly "+" sucks with sed).

Read more...

posted by ube in Linux and have No Comments

7 deadly sins of regexp

Lust /(.*?)/
Gluttony /(.{1,})\b/
Greed /^.*$/
Sloth http://www.amazon.com/Regular-Expression-Pocket-Reference-Expressions/dp/0596514271/ref=pd_bbs_sr_2?ie=UTF8&s=books&qid=1229670757&sr=8-2
Wrath s/.*//g
Envy FUCK IT!
Pride /(\((?:[^()]++|(?-1))*+\))/

Tags:
posted by ube in just for fun and have No Comments

validating user names sucks!

You know when you're writing any application, and you want to restrict the characters in the user name? Instead of checking for non allowed characters, look for allowed. Sounds strange? Not really, you'll understand:

function checkname($string, $allowed) {
$allowed = "/[$allowed]/s";
$string = preg_replace($allowed, "", $string);
if ( $string )
return FALSE;
else
return TRUE;
}

So what you'll do is remove all allowed characters, and if there are any left in the string the user has chosen an invalid username. Ofcourse it's regexp that does the trick. Using the code:

if ( ! checkname($input, "A-Za-z0-9_\.") )
echo "Invalid username!";
else
echo "Ok, lets go!

We're allowing A-Z, a-z, 0-9, underscore and dots in the username.

posted by ube in PHP and have No Comments