[vox-tech] Regexp Question

Jeff Newmiller vox-tech@lists.lugod.org
Thu, 8 Jan 2004 15:56:20 -0800 (PST)


On Thu, 8 Jan 2004, Richard Crawford wrote:

> I'm writing a Perl script which will go through all of the files in a
> directory and delete all of the text between <FORM and RESET>.  In each
> file, there are about ten lines of text between the two strings.  This has
> been breaking my head for a couple of hours now.  Anyone got any
> suggestions?

#!/usr/bin/perl -w
use strict;
$/='';       # no record separator
my $x = <>;  # process stdin to a single string
$x =~ s/<FORM.*?RESET>//sg; # substitute nothing where the minimal match
                            # occurs, disregard newlines, repeat
                            # throughout entire string
print $x;    # ship result to stdout

works regardless of where in the lines the form and reset tags are.

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------