PHP: regular expressions, preg match all function

PHP, as befits a modern programming language, offers the developer a set of functions for using regular expressions. You can search for occurrences of lines in other lines by complex criteria.

preg match all




HTML, CSS, XML and other formalized files are classic tasks for applying the preg match all function. No less effective is the search for addresses, surnames, phone numbers, e-mail and other information in informal texts.

Function Format

PHP : preg match preg match all. , - . " ". - " ", - " ". "" , - "" . , . .

php preg match all




- , . - matches. preg match all :





  • PREG_PATTERN_ORDER;
  • PREG_SET_ORDER.

( ). .

-

, . , "". "", : .

- , , . , . , .

  • - - .
  • a-z - , , a z - .
  • 0-9 - , , 1-3 - 1, 2 3.

. . , .

PHP preg match all . , :

  • [abc] a, b, c.
  • [^ABC] , A, B, C.
  • \w \W - .
  • \s \S - .
  • \d \D - .

php preg match all








- {n,m} .

  • n " ";
  • m - " ".

, , , , .

, , , , "^" , "$" - , . , preg match all. PHP , .

:

  • "/[0-9]*/"

, ("+", "-"), / :

  • /^[\s|\+|\-]{0,1}[0-9]*/

:

  • /^[\s|\+|\-]{0,1}[0-9]*(\.)[0-9]*/ - .
  • /[0-9a-z_-]+@[0-9a-z_^\.]+\.[a-z]{2,3}/ - e-mail.

preg match all, , .

preg match all examples




. , . , . PHP preg match all, , , .




All Articles