Title sums it up, lemme me try to give you a brief rundown. I made the (Pseudo)-
Spanglish Translator. But I happened to notice a bug when I was use it, it kills the stylesheet links.
Original Regexes:
$text =~ s#src=\"(.*?)\"#&resolveimg($1)#sige;
$text =~ s#href\=\"(.*?)\"#&resolvehref($1)#sige;
What I want is that if it's an image link (
img src="blah") or an css stylesheet link (
link href="blah") to use the the subroutine
&resolveimg on it, for the rest of the links (
a href="blah") I want to use
&resolvehref.
This is what I *tried* to come up with:
$text =~ s#(?:img.*?src|link.*?href)\=\"(.*?)\"#&resolveimg($1)#sige;
$text =~ s#(?:a.*?href)\=\"(.*?)\"#&resolvehref($1)#sige;
Which doesn't seem to work very well as I'm getting some rather strange output. TIA.
Edit:ysth's solution has been the closest match so far, quick edit gives me:
$text =~ s#(\bimg\b[^<>]*src|\blink\b[^<>]*href)\=\"(.*
+?)\"#$1 . "=\"" . &resolveimg($2) . "\""#sige;
$text =~ s#(?:\ba\b[^<>]*href)\=\"(.*?)\"#&resolvehref
+($1)#sige;
20031110 Edit by jeffa: Changed title from 'YaRP (Yet another Regex Problem) '
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.