From: Ilya Zakharevich Date: Wed, 8 Jul 1998 01:30:15 +0000 (-0400) Subject: Switch modifiers in RE off X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ca9dfc883b7dc3204e375cea5d38c48cb1715f83;p=p5sagit%2Fp5-mst-13.2.git Switch modifiers in RE off Message-Id: <199807080530.BAA14072@monk.mps.ohio-state.edu> p4raw-id: //depot/perl@1375 --- diff --git a/pod/perlre.pod b/pod/perlre.pod index f6fdc29..c72a71c 100644 --- a/pod/perlre.pod +++ b/pod/perlre.pod @@ -277,6 +277,8 @@ C<)> in the comment. =item C<(?:pattern)> +=item C<(?imsx-imsx:pattern)> + This is for clustering, not capturing; it groups subexpressions like "()", but doesn't make backreferences as "()" does. So @@ -288,6 +290,15 @@ is like but doesn't spit out extra fields. +The letters between C and C<:> act as flags modifiers, see +L>. In particular, + + /(?s-i:more.*than).*million/i + +is equivalent to more verbose + + /(?:(?s-i)more.*than).*million/i + =item C<(?=pattern)> A zero-width positive lookahead assertion. For example, C @@ -448,7 +459,7 @@ Say, matches a chunk of non-parentheses, possibly included in parentheses themselves. -=item C<(?imsx)> +=item C<(?imsx-imsx)> One or more embedded pattern-match modifiers. This is particularly useful for patterns that are specified in a table somewhere, some of @@ -464,6 +475,8 @@ pattern. For example: $pattern = "(?i)foobar"; if ( /$pattern/ ) { } +Letters after C<-> switch modifiers off. + These modifiers are localized inside an enclosing group (if any). Say, ( (?i) blah ) \s+ \1 diff --git a/regcomp.c b/regcomp.c index 6292466..663933d 100644 --- a/regcomp.c +++ b/regcomp.c @@ -982,6 +982,9 @@ reg(I32 paren, I32 *flagp) /* Make an OPEN node, if parenthesized. */ if (paren) { if (*regcomp_parse == '?') { + U16 posflags = 0, negflags = 0; + U16 *flagsp = &posflags; + regcomp_parse++; paren = *regcomp_parse++; ret = NULL; /* For look-ahead/behind. */ @@ -1117,11 +1120,24 @@ reg(I32 paren, I32 *flagp) break; default: --regcomp_parse; + parse_flags: while (*regcomp_parse && strchr("iogcmsx", *regcomp_parse)) { if (*regcomp_parse != 'o') - pmflag(®flags, *regcomp_parse); + pmflag(flagsp, *regcomp_parse); + ++regcomp_parse; + } + if (*regcomp_parse == '-') { + flagsp = &negflags; ++regcomp_parse; + goto parse_flags; } + regflags |= posflags; + regflags &= ~negflags; + if (*regcomp_parse == ':') { + regcomp_parse++; + paren = ':'; + break; + } unknown: if (*regcomp_parse != ')') FAIL2("Sequence (?%c...) not recognized", *regcomp_parse); diff --git a/t/op/re_tests b/t/op/re_tests index 78d89be..7ac20c3 100644 --- a/t/op/re_tests +++ b/t/op/re_tests @@ -359,6 +359,35 @@ a(?:b|(c|e){1,2}?|d)+?(.) ace y $1$2 ce ((?i)a)b Ab y $&:$1 Ab:A (?:(?i)a)b aB n - - ((?i)a)b aB n - - +(?i:a)b ab y $& ab +((?i:a))b ab y $&:$1 ab:a +(?i:a)b Ab y $& Ab +((?i:a))b Ab y $&:$1 Ab:A +(?i:a)b aB n - - +((?i:a))b aB n - - +'(?:(?-i)a)b'i ab y $& ab +'((?-i)a)b'i ab y $&:$1 ab:a +'(?:(?-i)a)b'i aB y $& aB +'((?-i)a)b'i aB y $&:$1 aB:a +'(?:(?-i)a)b'i Ab n - - +'((?-i)a)b'i Ab n - - +'(?:(?-i)a)b'i aB y $& aB +'((?-i)a)b'i aB y $1 a +'(?:(?-i)a)b'i AB n - - +'((?-i)a)b'i AB n - - +'(?-i:a)b'i ab y $& ab +'((?-i:a))b'i ab y $&:$1 ab:a +'(?-i:a)b'i aB y $& aB +'((?-i:a))b'i aB y $&:$1 aB:a +'(?-i:a)b'i Ab n - - +'((?-i:a))b'i Ab n - - +'(?-i:a)b'i aB y $& aB +'((?-i:a))b'i aB y $1 a +'(?-i:a)b'i AB n - - +'((?-i:a))b'i AB n - - +'((?-i:a.))b'i a\nB n - - +'((?s-i:a.))b'i a\nB y $1 a\n +'((?s-i:a.))b'i B\nB n - - (?:c|d)(?:)(?:a(?:)(?:b)(?:b(?:))(?:b(?:)(?:b))) cabbbb y $& cabbbb (?:c|d)(?:)(?:aaaaaaaa(?:)(?:bbbbbbbb)(?:bbbbbbbb(?:))(?:bbbbbbbb(?:)(?:bbbbbbbb))) caaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb y $& caaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb '(ab)\d\1'i Ab4ab y $1 Ab