Re: Regexp - alternate match and grouping



Witold Rugowski <rugowski1spm@xxxxxx> wrote in comp.lang.perl.misc:
Paul Lalli wrote:
As opposed to Frankenstein-ing your one single regular expression even

It wont be such a monster ;-)) since changes in format are in header
only, so most of information is taken by not showed part of regexp (PIX
syslog messages).

This case is probably easier to do with many regexps as You suggest
(file format is constant so ifs can recognize right format on the
beginning, and then all can be done without additional ifs), however I
can imagine data format for which would very convenient to do such
alternate grouping.

Is this possible?

If the corresponding parts are in the same sequence in all cases,
maybe. But, if I remember your data right, they aren't. Since
parentheses also count from left to right, you can't capture a
late match in an early capture, so no.

Anyway, when using regular expressions, your first interest (after
making them work) is to keep them manageable, which means keeping them
small. It is just a bad idea to combine regexes without need.

I'd go along these lines: Build a regex for each case that matches
the specific case, and let it capture the relevant parts whichever
way. Then assign the captures to named variables that are listed
in the sequence the specific pattern of captures needs. Here is
an example using simplified data:

while ( <DATA> ) {
my( $animal, $fruit);
( $animal, $fruit) = /^case1\s+(\w+)\s+(\w+)/ or
( $fruit, $animal) = /^case2\s+(\w+)\s+(\w+)/ or next;
print "animal: $animal, fruit: $fruit\n";
}

__DATA__
case1 horse orange
case2 apple cat
case2 banana snake
case1 cow tomato

That way the regexes for different cases stay apart, and you get to
maintain the regex and the corresponding sequence of variables on a
single line.

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
.



Relevant Pages

  • Re: Optimum settings for TMPGEnc?
    ... let's suppose I'd like to process those captured clips in various ways before encoding them to the MPEG-2 format and making a DVD out of them. ... I could capture the s-video signal using the pass-through feature of my DV camcorder. ... I could capture the s-video signal using a tv tuner card These kind of cards typically allow accessing the captured video data in uncompressed, ...
    (rec.video.desktop)
  • RE: Aspect ratio and format for future
    ... If your camcorders videochip is tuned to 4:3 then you will get best quality ... makes 16:9 video with a 4:3 chip but I don't know if anyone is doing this). ... what quality you get when you set you camcorder to capture in 16:9. ... > FILE FORMAT ...
    (microsoft.public.windowsxp.moviemaker)
  • Re: Movie Maker lost the abiliy to capture in DV-AVI from a camcorder
    ... I started capture in at least one other format, ... Note that the camera uses a USB connection. ... maker automatic codec download was off. ...
    (microsoft.public.windowsxp.moviemaker)
  • Re: Logging components?
    ... > also great for remote debugging - you can deploy the capture system, ... Then you'd drop a log component for each exception format you want, ... <frequency of occurence >, ...
    (borland.public.delphi.thirdpartytools.general)
  • RE: Movie Maker lost the abiliy to capture in DV-AVI from a camcorder
    ... I did notice the WMV ... I started capture in at least one other format, ... maker automatic codec download was off. ...
    (microsoft.public.windowsxp.moviemaker)