Been struggling with a regexp using perl since I couldn't get sed to work as I wanted (mainly "+" sucks with sed).
16
Jan
Perl 5.8.8 sucks, or the lack of Perl 5.10 on my box sucks! Really
posted by ube in Linux and have No Comments
19
Dec
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: RegExp
posted by ube in just for fun and have No Comments
02
Oct
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
Tags
Apple Arlanda Audiobooks Canada Code Poetry England faac Firefox first post Heatrow iPhone iPod iTunes Javascript job Links Linux London Mac mdadm Montreal mpg321 MySQL Named Capture Netbook On the plane pacemaker PC Perl PHP Picture RAID Reading RegExp Server Stockholm Sucks! (Really!) Sundsvall Sweden Tips Travel Traveling tv.autopsy.se Unix WordpressDemoscene
projects
Categories
Twitter
- @mgroth function returnNull() { return NULL; } 2 days ago
- @Soranismail kan vi inte leka Robinson och rösta ut honom? 2 days ago
- @ drakborgen.. Var e singelmorsorna? 3 days ago
- Foto: Stjärnfotograf http://photos.autopsy.se/stjarnfotograf/ 5 days ago
- Väger 10 kilo mindre än för 18 år sen, och 37 kilo mindre än för 8 år sen. Lite stolt kan man väl vara? 5 days ago
© blog.autopsy.se 2009 | Created by Jay Hafling.
Powered by WordPress