Forget complicated regex. For this you can use rindex / substr:
use strict; use warnings; my $regex = '\default\main\TSDEMO\WORKAREA\tsdemo_intranet\TSDEMO\imag +es\corner'; my $website = 'TSDEMO'; my $parent = substr($regex, rindex($regex, $website)); print $parent;
(note that this gives TSDEMO\images\corner with no leading \, since you don't have $website as \TSDEMO)

Or if you really MUST have case insensitive matching - which doesn't make sense because file paths are sensitive - you can make uppercase copies of the original string and use those:

use strict; use warnings; my $regex = '\default\main\TSDEMO\WORKAREA\tsdemo_intranet\TSDEMO\imag +es\corner'; my $website = 'TSDEMO'; my $tregex = uc($regex); my $parent = substr($regex, rindex(uc($regex), uc($website))); print $parent;
BTW, what you're asking for is the third match, not the second. With case insensitive matching, tsdemo from tsdemo_intranet also matches.

In reply to Re: Retrieve second occurrence and everything afterwards using regex by TedPride
in thread Retrieve second occurrence and everything afterwards using regex by luked

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.