Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Interpolate Text Not Inside a Certain Tag

by jonadab (Parson)
on Apr 07, 2005 at 17:25 UTC ( #445800=note: print w/replies, xml ) Need Help??

in reply to Interpolate Text Not Inside a Certain Tag

First off, dragonchild's answer is well worth considering, and probably the better choice. But for the sake of interest... I think it may be possible to do this with a regex, provided the problem really is as simple as the way you have stated it and not complicated by additional nesting or somesuch. Something along these lines...

s!(?:(?:([']{2})([^']+)[']{2})|(?:([*]{2})([^'*]+)[*]{2}))!($3 eq '**')?"<b>$4</b>":$2!ge;

...might work. (No, lots of paretheses don't bother me. Yep, I knew a lisp variant before I learned Perl.) But dragonchild's solution is easier to read and maintain.

update: fixed silly paren-counting error

"In adjectives, with the addition of inflectional endings, a changeable long vowel (Qamets or Tsere) in an open, propretonic syllable will reduce to Vocal Shewa. This type of change occurs when the open, pretonic syllable of the masculine singular adjective becomes propretonic with the addition of inflectional endings."  — Pratico & Van Pelt, BBHG, p68

Replies are listed 'Best First'.
Re^2: Interpolate Text Not Inside a Certain Tag
by ikegami (Pope) on Apr 07, 2005 at 17:37 UTC
    It doesn't work for the simple case "**bold**". I haven't tried anything else.

      Yeah, I wasn't thinking and used the match variables as if there were only two sets of parens, rather than four. The updated version works for that simple case. However, I'd worry about unexpected data screwing it up potentially rather badly, and it only handles one type of quote mark; if you're allowed to have both single and double quote marks and nest them and escape quote marks within quotes with backslashes, stuff gets messy fast.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://445800]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2020-09-23 11:07 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (131 votes). Check out past polls.