I'm not sure I understand what problem you are trying to describe -- the sample input string you showed (
\caption{*}) turns into the output you want (
<caption>*</caption>) using the code snippet as originally posted. Maybe if you showed the particular input sample that causes a problem for you?
Anyway, I'd probably write the regex a little differently -- this would behave a bit different from the OP version, in allowing the input to have an empty string (i.e. nothing) inside the curly braces (whereas the OP would not match unless there's at least one character in there):
s# \\ (caption) \{ ([^}]*) \} #<$1>$2</$1>#gisx;
That also works on the sample input string you originally posted. If you have a string that doesn't work with that, show us.
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.