more useful options | |
PerlMonks |
Extracting multiple-asterisk-delimited substring with Text::Balancedby kba (Sexton) |
on Dec 25, 2008 at 22:08 UTC ( [id://732610]=perlquestion: print w/replies, xml ) | Need Help?? |
kba has asked for the wisdom of the Perl Monks concerning the following question:
greetings, perl people,
I'm writing a parser for generic lightweight markup, that is agnostic to the different flavours (Textile, reST, Wikimedia, Creole etc.). Therefore it heavily relies on plugins. The Block Parser works fine by now, but the Inline Parser (for typography, links, footnotes etc.) is giving me headaches, because of Text::Balance's animosity towards regexp-metacharacters.
How can I match a string delimited by double asterisk ('**') with Text::Balanced? Suppose I have this stringand I want to use extract_tagged to extract the bold words part. My first try:
Now perl complains about nested qualifiers because Text::Balanced creates a regex that starts with /\G**. So I try escaping the '*'s:
That leads to a 'quantifier follows nothing' regexp error. Okay, double escape it, methinks, but that gives the same error, 'quantifier follows nothing' in the regexp Text::Balance creates. When I try it with three or more '\'s, there are neither errors nor results and I am thoroughly confused because of all the escaping of escaping chars, I played around with quotemeta, but that didn't work either so I turn to you: Is there a way to match a string delimited by multiple regexp metacharaters like '*' and if so, what would be the least confusing way to implement it? Thanks in advance and merry kwanzaakba
Back to
Seekers of Perl Wisdom
|
|