Retrieve email using regex
ThisĀ horrendousĀ regular expression will parse a string and return a valid email address from it. $email = “<’Freddy’> fred@live.com”; preg_match(‘/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/’, $email, $match); echo $match[0]; This will return: fred@live.com Basically, if you pass an array as the third parameter of the preg_match method, it will be filled with the preg_match results, and the first item of the [...]
Online regex -> php tool
I’ve found an excellent online tool, where you can give it a regex, and it will spit out the PHP syntax for use with preg_replace, preg_match, etc. I’m forever getting ‘Unknown modifier’ errors when trying to insert regex’s into my PHP code. This sorts it out for you. http://regex.larsolavtorvik.com/
Regex – “The” searching
Say you have a list of movie titles, and you want to either sort them, or search through them, and some of them have “The ” at the start, for example: The Simpsons Simpson Street When doing a MySQL search: SELECT * FROM movies WHERE title LIKE “The Simp%”; Would only return the first row. [...]
REGEX – Remove Letters from string
Removing letters from a string using Regular Expressions. Very simple. but brain bending – All I wanted to do was remove a prefix from a string. The prefix was always letters, and I only wanted the numerical suffix returned, so though, preg_replace was my best bet. echo preg_replace(“/[a-zA-Z]*/”, ”, ’12345MystrING67890′); This returns : 1234567890 Perfect.
Online Regular Expression Testing Tool
Regular expressions — everyone loves them, right? Well, I am currently running Ubuntu, and I would normally use RegexBuddy – but cannot unless I use Wine, and I don’t really like to. So, I wanted to find an online solution for my needs. So, I found this one, that allows my to test my regular [...]