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 ****
In reply to Re: Help with Multiple line RegEx
by gargle
in thread Help with Multiple line RegEx
by blackadder
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |