use strict;
my $str = '<div class="blog-list-item blog"><header class="entry-title">
<h1>Welcome to our website</h1>
</header><article id="entry-72" class="entry post-72 page et-bg-layout-dark et-white-bg"><div class="jumbotron row">
<div class="col-md-8">
<ul>
<li>You have a pending job on your neck?…</li>
<li>Do your company need a website makeover ?…</li>
<li>Or a competitive web application ? ?…</li>
<li>Do you need a customized plugin, or a tweak ?…</li>
<li>Maybe you want a personal website ?…</li>
<li>Or a graphic for your new project ?…</li>
</ul>
<div class="bg-primary well">
<h4 class="text-center text-white shadow">Track your project as we work it to perfection...</h4>
</div>
</div>
<div class="pull-right col-md-4">
<h4 class="bg-primary text-white well">Other services we offer</h4>
{ACCESS{type=500}}
<ul>
<li>SEO work for an existing website or new</li>
<li>Bulk SMS</li>
<li>E-currency exchange</li>
<li>Facebook AD</li>
<li>Google AD</li>
</ul>
{/ACCESS}</div>
{RAW{say=email,access=500}} {RAW} <a class="btn button large tall green" href="client-area">Place new Job now as we deliver at the quickest <em>reasonable time</em></a>{/RAW}</div></article></div>';
my $regex = qr~#opening tag
\{(RAW|ACCESS|DWNLINK|MODL|\w+)
#optional attributes
(?>
\{ ([^}]*) }
)?
}
#optional text and closing tag
(?:
( #text:= any char except "{", or a "{" not followed by /commandname
[^{]*+
(?>\{(?!/?\1[{}])[^{]*)*?
)
#closing tag
\{/\1}
)?~ixp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html