It depends on what you mean by 'e' followed by 'fg'.

your string: abcdefghijklfghijklabcdefg

Here is one example s/e.*fg/eXfg/;
abcdeXfg
As you see it took e, followed by anything, followed by fg and is greedy.

This is a little more like I think you want s/efg/eXfg/g;
abcdeXfghijklfghijklabcdeXfg
This looks for efg, the g modifier tells it to keep looking (global)

or perhaps you meant this s/e[^e]*fg/eXfg/g;
abcdeXfghijklabcdeXfg
This is e followed by zero or more non e characters followed by fg, searched for multiple times.

here is a generic search for p1 followed by p2, by p3, with things that are not the patterns in between. s/p1[^(p1)(p2)(p3)]*p2[^(p1)(p2)(p3)]*p3/X/g;
then I guess you just count the X's or use them as markers for further processing or whatever else you needed.

cheers.


In reply to Re: Regarding Regular Expressions by Random_Walk
in thread Regarding Regular Expressions by Sameet

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.