Hiya - dot star will match *anything* (update: will match anything in your case because you've used /s, but normally doesn't match \n - good point tilly), you want to match *anything except a quote*. So you want ([^"]*)

What's going wrong at the moment is this: some of your links have the 'group' parameter, some don't. Consider the case of one which doesn't, followed by one which does. So the text is

<a href="http://www.foo.com/">Foo</a> wibble <a href="http://www.bar.c +om/" groups="1,2,3">Bar</a>
Your first match will be
$1= http://www.foo.com/">Foo</a> wibble <a href="http://www.bar.com/ $2= 1,2,3 $3= Bar
i.e. the problem is that if a tag *doesn't* have the 'group' parameter, then the first .* will swallow all the text until it can find
" group= etc...
which will be in the *next* 'a' tag that *does* have a 'group'.

Even without dot star, this solution isn't too robust - what if the someone misses out a quote mark (and people will in HTML)? You might want to think of a different WTDI.

andy.

update: and physi is right, you either need to escape the slash e.g. <\/a> or use a different delimiter for your regexp e.g. s#original#substitute#isge

update2: have a look at HTML::Parser and maybe template toolkit. Any monks have other ideas?

update3: Text::TagTemplate? (never used it though, don't know if it's any good) - you could use this module to define your own tag e.g. <#GROUPLINK href="http://whatever.com" group="1,2,3" text="click here for link"> so that it called your change() subroutine when it found the special tag. Then the module would parse the HTML for you.

The reason why it's a good idea to get a module to parse the HTML for you is that it's surprisingly difficult to do correctly. E.g. what if the tag is inside a comment? what if the tag reads <a group="1,2,3" href="whatever">? If you're going to be the only one writing the HTML, then you're probably OK with a regexp - otherwise you probably do need to use a module. In any case, good luck with it. andy.


In reply to Re: regex and dot to star by andye
in thread 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.