- 论坛徽章:
- 46
|
回复 6# sunzhiguolu
就是个空的这东西。 Perl 文档很完备,关于语言本身有 perldoc 不需要搜索引擎,我贴的都是 perldoc 里的内容。
http://perldoc.perl.org/perlre.html#Extended-Patterns
(?adlupimsx-imsx)
(?^alupimsx)
One or more embedded pattern-match modifiers, to be turned on (or turned off, if preceded by - ) for the remainder of the pattern or the remainder of the enclosing pattern group (if any).
This is particularly useful for dynamic patterns, such as those read in from a configuration file, taken from an argument, or specified in a table somewhere. Consider the case where some patterns want to be case-sensitive and some do not: The case-insensitive ones merely need to include (?i) at the front of the pattern. For example:
$pattern = "foobar";
if ( /$pattern/i ) { }
# more flexible:
$pattern = "(?i)foobar";
if ( /$pattern/ ) { }
These modifiers are restored at the end of the enclosing group. For example,
( (?i) blah ) \s+ \g1
will match blah in any case, some spaces, and an exact (including the case!) repetition of the previous word, assuming the /x modifier, and no /i modifier outside this group.
These modifiers do not carry over into named subpatterns called in the enclosing group. In other words, a pattern such as ((?i)(?&NAME)) does not change the case-sensitivity of the "NAME" pattern.
Any of these modifiers can be set to apply globally to all regular expressions compiled within the scope of a use re . See '/flags' mode in re.
Starting in Perl 5.14, a "^" (caret or circumflex accent) immediately after the "?" is a shorthand equivalent to d-imsx . Flags (except "d" ) may follow the caret to override it. But a minus sign is not legal with it.
Note that the a , d , l , p , and u modifiers are special in that they can only be enabled, not disabled, and the a , d , l , and u modifiers are mutually exclusive: specifying one de-specifies the others, and a maximum of one (or two a 's) may appear in the construct. Thus, for example, (?-p) will warn when compiled under use warnings ; (?-d:...) and (?dl:...) are fatal errors.
Note also that the p modifier is special in that its presence anywhere in a pattern has a global effect.
|
|