Hi brothers, I am made some script which read html template file, in which are some hyperlinks at this syntax:

<a href="http://my.domain.com" group="1,2,5">This URL</a>

scipts validate users from cookie (in which it found usergroup value) Now script should check all hyperlink - if usergroup (which was in the cookie) is in html hyperlink as: group="value" then remove group parameter from it and print simple this:

<a href="http://my.domain.com">This URL</a>

If not script should print only This URL. There is several hyperlink in html template.

So expect that I get from cookie usergroup value and read html source from file into the $html.

$html =~ s/<a href="(.*?)" group="(.*?)">(.*?)</a>/&change($1, $2, $3) +/isge; print $html; sub change { my ( $group, $temp, $url, $hyp, @groups ); $url = @_[0]; $hyp = @_[2]; @groups = split( /,/@_[1] ); foreach $group (@groups) { if ($group == $usergroup) { $temp = "<a href=\"$url\">$hyp</a>"; return $temp; } return $hyp; } }

This is long version I know that it can be written by short way but this is test... Its working in some case but in some not. Sometimes it print only part of my template, sometimes all. It depent on html template source. When all hyperlinks have groups parameter results is different from when only some hyperlinks have group parameter... So probably problem will be in regex..... I read Death to dot star from Ovid but doesn't found answer in it....

So If you know something.... I wrote code from my memory So I hope that it's allright...

Li Tin O've Weedle
mad Tsort's philosopher


In reply to regex and dot to star by LiTinOveWeedle

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.