I do not know the reason why the big regular expression is used (and where it is from) to check if a string is an IPv6 address. Also I am not sure why the regular expression tries to match a string with optional whitespace characters at the beginning and end of it.
But I think filter_var with the correct flags is a much better and faster solution.
See the time values at https://3v4l.org/FS5fJ
- The topic ‘Use filter_var instead of preg_match (much better performance)’ is closed to new replies.