swift has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I am learning perl. When I use a Regexp::Assemble module i have a little bit doubt.

I Created Regexp for the following:

use Regexp::Assemble; my $ra=Regexp::Assemble->new; $ra->add('Text.'); $ra->add('TEXT.'); $ra->add('Texts'); print $ra->re;

I got the output

(?-xism:T(?:EXT.|ext.))

Please teach me what is mean by ?-xism:

Thank You

Retitled by g0n from 'Regexp::Assemble'.

Replies are listed 'Best First'.
Re: Explain output produced by Regexp::Assemble
by polypompholyx (Chaplain) on Aug 03, 2005 at 08:50 UTC

    They're the same as the x (extended space-insensitive), i (case insensitive), s (single line, allow . to match \n.), and m (multi line, allow ^ and $ to match around \n) modifiers you can put on the end of a regex m// match.

    When you save a modified regex using quote-regex (which Regex::Assemble uses internally), like this $regex = qr/foo/ix, these flags need to be set within the $regex, particularly because you might well incorporate it into a larger quoted regex at some later point, like this: $fwibble = qr/$regex|something_else/. The flags are only in operation for the first part of this new regex, but not for something_else.

    The flags ahead of the dash are the ones in operation within the scope of the enclosing parentheses. So (?-xism:foo) means that none of the flags are in operation when trying to match 'foo'. (?misx:foo) would mean all of them are in operation, and (?ix-sm:foo) would mean only i and x were.

Re: Explain output produced by Regexp::Assemble
by umbra (Acolyte) on Aug 03, 2005 at 07:44 UTC
    As far as I understand pattern

    ?:something

    means something is a pattern to be tested for. -xism is just re engine parameters, described in perlre

      As far as I understand pattern

      ?:something

      means something is a pattern to be tested for.

      Not quite. What you quoted is incomplete. It should be

      (?:something)
      and it tells the regex engine that the parentheses should be used only for grouping, and not for capturing a submatch in one of $1, $2, etc.

      the lowliest monk