Have you tried something until now? the answer hevily depends on rules of the pattern and the string composition.
But something almost simple like this can suffice (pay attention to the [^AX] part: it may need to be more elaborate).
# warning win32 doublequotes oneliner perl -e " print $1 if $ARGV[0]=~/(AAA)[^AX].+XXX/" ABBBAAACCCXXX AAA
that explained by YAPE::Regex::Explain becomes:
perl -MYAPE::Regex::Explain -e " print YAPE::Regex::Explain->new(qr/(A +AA)[^AX].+XXX/)->explain(); " The regular expression: (?-imsx:(AAA)[^AX].+XXX) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- AAA 'AAA' ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- [^AX] any character except: 'A', 'X' ---------------------------------------------------------------------- .+ any character except \n (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- XXX 'XXX' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
L*
In reply to Re: Grep the first occurrence of a string above a reference string
by Discipulus
in thread Grep the first occurrence of a string above a reference string
by venkat1312
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |