Regex for Twitter username

Posted by & filed under Coding.

Working on a small weekend project I needed an easy way to validate that a string contained a valid Twitter username. Not necessarily an active account, but that could be an account. Found the rules on Twitter’s site that a username can be between 1 and 15 characters and can contain only the characters A-Z,… Read more »

One line preg_match for PHP

Posted by & filed under Code Tips.

For a project I’ve been working on I needed to use preg_match quite a bit. But I got really tired of having to punch in several lines, so I cooked up this little snippet to pull out a specific match group. $pattern and $search work just like normal preg_match. The $group parameter tells it which… Read more »

One line PHP regex search

Posted by & filed under Coding.

Not sure this is the best way to do this, but it works. Working on a project and I’m writing a lot of code to do RegEx searches. Each match is 3 or 4 lines to do the match, check if there was a match, and then do something with the match. Since I was… Read more »

Regex to replace multiple spaces

Posted by & filed under Programming.

Normally I just don’t worry about this since I’m usually building websites and HTML takes care of merging multiple spaces. But it comes up occasionally. And since it’s just a quick regex replace, it’s pretty quick to merge multiple spaces. Piece of cake. It looks for any places that there is 2 or more spaces and… Read more »

Pocket Reference for RegEx

Posted by & filed under Programming.

Not that it happens often, but every now and then I actually clean off my desk. It’s one of those things that I sort of know intuitively that I work much better with clean desk. This book on regular expressions, one of the Pocket Guide series by O’Reilly, is one that tends to always be… Read more »