Jump to content

Winstons

Members
  • Posts

    52
  • Joined

  • Last visited

    Never

Everything posted by Winstons

  1. Your RegExp is big and bad. Try my code $str = 'www.google.com http://google.com https://google.com http://www.google.com https://www.google.com google.co.uk www.google.co.uk http://google.co.uk https://google.co.uk http://www.google.co.uk https://www.google.co.uk'; preg_match_all("#((?:https?://)?(?:www\.)?[-a-z\d]{1,9}\.[-a-z\d]{2,5}(?:\.[-a-z\d]{2,4})?)#is", $str, $match); echo '<pre>'.htmlspecialchars(print_r($match, 1)).'</pre>'; Result is Array ( [0] => Array ( [0] => www.google.com [1] => http://google.com [2] => https://google.com [3] => http://www.google.com [4] => https://www.google.com [5] => google.co.uk [6] => www.google.co.uk [7] => http://google.co.uk [8] => https://google.co.uk [9] => http://www.google.co.uk [10] => https://www.google.co.uk ) [1] => Array ( [0] => www.google.com [1] => http://google.com [2] => https://google.com [3] => http://www.google.com [4] => https://www.google.com [5] => google.co.uk [6] => www.google.co.uk [7] => http://google.co.uk [8] => https://google.co.uk [9] => http://www.google.co.uk [10] => https://www.google.co.uk ) )
  2. Modificator 's' - ignoring chars of new line "\r\n" or "\n". Modificator 'i' - ignoring the case of letters. JavaScript haven't the modifocator 's', instead of this use modif. 'g' Try this var partTest = /(?:^| )((?:\d+[a-z]|[a-z]+\d)[a-z\d]+)/gi;
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.