Understanding the preg_match() function pattern

HI,
Please someone help me to explain the following preg_match () function pattern:
(!preg_match(“/\b(?:(?:https?|ftp)://|www.)[-a-z0-9+&@#/%?=~|!:,.;]*[-a-z0-9+&@#/%=~|]/i”,$website));

thanks
Sariful

what part are you having problems with?

always worth a look when RegExp are concerned: http://regular-expressions.info

Check this out https://regex101.com/r/tR0nC5/1.
I posted it in there and added a domain.

You can read on the right hand side what each part does.

It looks like the pattern is trying to match a url starting with http(s)://, ftp://, or www. It also looks like if the string starts with http or ftp, it will catch the www. If this doesn’t help, please enlighten us on what exactly you don’t understand.

Its the pattern that used to be used to validate URLs before PHP implemented filters.

It is equivalent to:

filter_var($website, FILTER_VALIDATE_URL)

but has a greater potential for typos.

Are all constants of filters available in any php version with filter extension?

no.

see the changelog section in the filter constants’ manual pages.

They are in all the currently supported versions of PHP - 5.6 and 7.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.