Это очень просто. Быстрый просмотр документации ответит на ваши вопросы. Вы также можете найти YAPE :: Regex :: Explain полезным.
$ perl -MYAPE::Regex::Explain -e'
print YAPE::Regex::Explain->new($_)->explain
for
qr/ABC (?i:s) XYZ/,
qr/ABC (?x: [A-Z] \.? \s )?XYZ/,
qr/ABC (?ix: [A-Z] \.? \s )?XYZ/,
qr/ABC (?x-i: [A-Z] \.? \s )?XYZ/i;
'
& # x20;
The regular expression:
(?-imsx:ABC (?i:s) XYZ)
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
ABC 'ABC '
----------------------------------------------------------------------
(?i: group, but do not capture (case-
insensitive) (with ^ and $ matching
normally) (with . not matching \n)
(matching whitespace and # normally):
----------------------------------------------------------------------
s 's'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
XYZ ' XYZ'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
& # x20;
The regular expression:
(?-imsx:ABC (?x: [A-Z] \.? \s )?XYZ)
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
ABC 'ABC '
----------------------------------------------------------------------
(?x: group, but do not capture (disregarding
whitespace and comments) (case-sensitive)
(with ^ and $ matching normally) (with .
not matching \n) (optional (matching the
most amount possible)):
----------------------------------------------------------------------
[A-Z] any character of: 'A' to 'Z'
----------------------------------------------------------------------
\.? '.' (optional (matching the most amount
possible))
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
)? end of grouping
----------------------------------------------------------------------
XYZ 'XYZ'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
& # x20;
The regular expression:
(?-imsx:ABC (?ix: [A-Z] \.? \s )?XYZ)
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
ABC 'ABC '
----------------------------------------------------------------------
(?ix: group, but do not capture (case-
insensitive) (disregarding whitespace and
comments) (with ^ and $ matching normally)
(with . not matching \n) (optional
(matching the most amount possible)):
----------------------------------------------------------------------
[A-Z] any character of: 'A' to 'Z'
----------------------------------------------------------------------
\.? '.' (optional (matching the most amount
possible))
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
)? end of grouping
----------------------------------------------------------------------
XYZ 'XYZ'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
& # x20;
The regular expression:
(?i-msx:ABC (?x-i: [A-Z] \.? \s )?XYZ)
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?i-msx: group, but do not capture (case-insensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
ABC 'ABC '
----------------------------------------------------------------------
(?x-i: group, but do not capture (disregarding
whitespace and comments) (case-sensitive)
(with ^ and $ matching normally) (with .
not matching \n) (optional (matching the
most amount possible)):
----------------------------------------------------------------------
[A-Z] any character of: 'A' to 'Z'
----------------------------------------------------------------------
\.? '.' (optional (matching the most amount
possible))
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
)? end of grouping
----------------------------------------------------------------------
XYZ 'XYZ'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------