Skip to content

Instantly share code, notes, and snippets.

@tom--
Last active December 14, 2015 02:49
Show Gist options
  • Select an option

  • Save tom--/5016388 to your computer and use it in GitHub Desktop.

Select an option

Save tom--/5016388 to your computer and use it in GitHub Desktop.
detecting urls
<?php
$letnum = '\p{L}\p{Mn}\p{Mc}\p{Nd}';
$sym = '+&@#/%=~_|$';
$pnct = '?!:,.-';
$c1 = "[$letnum$sym$pnct]";
$c2 = "[$letnum$sym]";
// then the regex pattern is, so to speak:
// \b(?: https?:// | www\. ) (?: \($c1*\) | $c1 )* (?: \($c1*\) | $c2 )
// with xui options.
// the resulting pattern is something like
'{
\b(?: https?:// | www\. )
(?: \([\p{L}\p{Mn}\p{Mc}\p{Nd}+&@#/%=~_|$?!:,.-]*\) | [\p{L}\p{Mn}\p{Mc}\p{Nd}+&@#/%=~_|$?!:,.-] )*
(?: \([\p{L}\p{Mn}\p{Mc}\p{Nd}+&@#/%=~_|$?!:,.-]*\) | [\p{L}\p{Mn}\p{Mc}\p{Nd}+&@#/%=~_|$] )
}xui'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment