Regular Expression Archive

This is my archive of regular expressions for use in php usually with the preg_match type functions. If you can improve on these I’d like to know as they are mostly just harvested from other sources as I need them and it’s possible they could be improved:

This code isn’t strictly correct as word press’s inbuilt editor modifies it – I’m trialing code highlighters at the moment to avoid this email me in the mean time for the correct version if you need it.

Match url in parts:
This is split into parts to make the components of the expression obvious for maintenance

  1.  
  2. $match_host = "([a-zd][-a-zd]*[a-zd].)*[a-z][-a-zd]*[a-z]";
  3. $match_port = "(:d{1,})?";
  4. $match_path = "(/[^?<>#"s]+)?";  
  5. $match_query = "(?[^<>#"s]+)?";  
  6. $match_url = "/(?:(?<=^)|(?<=s))((ht|f)tps?://" . $match_host . $match_port . $match_path . $match_query .")/";
  7.  

Convert Multiple Spaces To a Single Space:
This is actually the way to convert any multiple elements to a single element :)

  1.  
  2. $message = preg_replace(‘/ss+/’, ‘ ‘, $message);
  3.  




Sphere: Related Content


0 Responses to “Regular Expression Archive”

  1. No Comments

Leave a Reply

You must login to post a comment.



-->

Handy Tools

Search for a domain name

Search for a taken domain name
Poker stars.net