preg_match

PHP 4, PHP 5, PHP 7, PHP 8
preg_match - Perform a regular expression match

Example #1 Getting the domain name out of a URL

Result: domain name is: php.net
PHP Version:

Example #2 Using named subpattern

Result: Array ( [0] => foobar: 2008 [name] => foobar [1] => foobar [digit] => 2008 [2] => 2008 )
PHP Version:

Example #3 Find the string of text "php"

PHP Version:

Example #4 Find the word "web"

PHP Version:


Example #5 of preg_match

PHP Version:


Function preg_match:

Regular Expressions (Perl-Compatible) Functions

Most used PHP functions