in reply to Help with Multiple line RegEx
Hi,
What about the following:
#!/usr/bin/perl use strict; use warnings; while (<DATA>) { # only check between --- show switchname --- and ***** if ( /^-+ show switchname -+/ .. /^\*+/ ) { # only pick up the word between these two lines print "$1\n" if /(^\w+)/; } } __DATA__ show tech-support details -------------------- show switchname ------------------ CCC217_ANG_GREEN ****************************************************************** show tech-support details -------------------- show switchname ------------------ CCC218_ANG_GREEN ****************************************************************** show tech-support details -------------------- show switchname ------------------ CCC219_ANG_GREEN ****************************************************************** show tech-support details -------------------- show switchname ------------------ CCC220_ANG_GREEN ******************************************************************
The code indicates clearly what it's about. We use .. to only look at 'blocks' in the file and then process the block lines with a regexp looking up a single word (the first word on the line actually).
---- show ---- doesn't begin with a word, and,
************** isn't a word either.
Using .. makes updating the code later on very easy. (Imagine that there are 2 lines between ---- and ****
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Help with Multiple line RegEx
by Skeeve (Parson) on Oct 10, 2005 at 11:13 UTC | |
Re^2: Help with Multiple line RegEx
by blackadder (Hermit) on Oct 10, 2005 at 11:32 UTC | |
by gargle (Chaplain) on Oct 10, 2005 at 11:55 UTC |