. .
PHP
:
.
. PHP
, , .
(regular
expressions). ,
.
. ,
-
, , , .
.
(regular expression,
regexp, ) - ,
,
. ,
regexp'
, ,
.. ,
,
, ,
.
,
, .
regexp ,
e-mail : /^\w+([\.\w]+)*\w@\w((\.\w)*\w+)*\.\w{2,3}$/
, , :-) ,
, , .
regexp' -
.
Unix Perl.
PHP
: POSIX- Perl-.
, Perl-
, , (
10 ).
Perl- . ,
,
, PHP Manual, 50 ,
, .
, ,
.
,
.
,
,
. ", ",
,
- .
, ,
, "3 4
5 ",
,
: /\d{3,4}\s[A-Z]{5}/
, ,
. ,
,
.
('/ '). :
/\d{3}-\d{2}/m , '/ '
, '\d{3}-\d{2} ' -
, 'm ',
- .
,
,
, (..
).
.
.
.
('\ '). ,
,
:
- -
,
.
,
, . '
. ',
" ",
'\. ' .
: '\\ '.
-
, ,
'
\ '.
'd ' ,
, ('\d ')
, " ".
,
.
, ,
, ,
, - .
:
|
|
, |
\n |
(
0x0A ) |
\r |
( 0x0D ) |
\t |
( 0x09 ) |
\xhh |
0xhh , \x41
'A ' |
|
\d |
(0-9) |
\D |
( 0-9) |
\s |
( ) |
\S |
(, ,
\s ) |
\w |
"" (, .
,
('_ ')) |
\W |
, ,
\w |
,
.
,
, . ,
, ,
,
.
Regexp |
|
/\d\d\d/ |
('123 ',
'719 ', '001 ') |
/\w\s\d\d/ |
, ( ) ('A
01 ', 'z 45 ', 'S 18 ') |
/\d and \d/ |
: '1 and 2 ', '9
and 5 ', '3 and 4 '. |
.
,
- .
'[] '.
,
, ,
.
,
. ,
,
.
, :
- ('
\ '). ..
.
- ('
- ').
(
'0-9 ')
- '
^ '.
( !)
. ..
, .
, , :
Regexp |
|
[0-9A-Fa-f] |
|
[\dA-Fa-f] |
, |
[02468] |
|
[^\d] |
, ( \D ) |
[a^b] |
'a ', 'b ',
'^ '. , '^ '
- ,
. |
.
,
( ).
'^ ' '$ '.
, , ,
.
'^ ' ,
, '$ ' ,
, .
, :
, : 12 aaa bbb
aaa 27 ccc
aaa aaa 45
:
/\d\d/m ( ).
3 :
'12 ', '27 ', '45 '.
, ,
: /^\d\d/m .
- '12 ',
. ,
/\d\d$/m '45 '.
'. '. ,
(
). ,
"" - .
/.bc/
'abc ' 'Abc ' 'Zbc '
'5bc '.
' '.
. : /( ) /
' '
' '.
. .
'( ' ') '.
. ,
-
. ,
,
,
.
.
,
-
.
, -
,
:
/( ) / .
-
:
( )
-
-
,
( ,
"
").
- -
, -
.
.
: ,
4
( ): ,
2
,
: ,
,
,
. ( -
), ,
.
'?: '
: /(?: ) / .
,
. , ,
: /\((\d{3,5})\)\s+(\d{3}-\d{2}-\d{2})/
. regexp
.
: /\((\d{3,5})\)\s+(\d{3}-\d{2}-\d{2})/
(
): /\((\d{3,5})\)\s+(\d{3}-\d{2}-\d{2})/
,
- ,
: /\((\d{3,5})\)\s+(\d{3}-\d{2}-\d{2})/
: /\((\d{3,5})\)\s+(\d{3}-\d{2}-\d{2})/
,
: /\((\d{3,5})\)\s+(\d{3}-\d{2}-\d{2})/
, 3 -
. ,
, -
. ..
!
, .
: "My phone is (095) 123-45-67 ".
3 : '(095) 123-45-67 ',
'095 ' '123-45-67 '.
,
(..
quantifiers). -
, -
. ,
,
, . ,
, .
,
.
.
'* '. ,
0 (..
). :
/ab*c/ 'ac ',
'abc ', 'abbc ' ..
'+ '. ,
1 (..
). :
/ab+c/ 'abc ',
'abbc ', 'abbbc ' ..,
'ac '.
'? '. ,
, ,
. : /ab?c/
'ac ' 'abc ',
'abbc '.
'{ ' '} '.
.
. ,
,
. :
{2,4} - 2 ,
4.
{,5} - (..
), ,
5 .
{3,} - 3 ,
.
{4} - 4
'? '. : /.+a/ .
,
'a ' .
,
'a '.
, ""
.
( ), "" ,
'? ' :
/.+?a/ .
.
-
,
. ,
.
|
|
i |
case-insensitive, ..
. |
m |
, , ,
.
,
. '^ '
'$ ' .
,
. |
s |
'. '
. ..
/.+/
, , .
. |
U |
" "
( "" .
) |
, .
, PHP ,
. |