kba has asked for the wisdom of the Perl Monks concerning the following question:
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.$str = '**bold words**'
My first try:
warn Dumper extract_tagged( $str, '**', '**', );
Now perl complains about nested qualifiers because Text::Balanced creates a regex that starts with /\G**. So I try escaping the '*'s:
warn Dumper extract_tagged( $str, '\*\*', '\*\*', );
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 kwanzaa
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extracting multiple-asterisk-delimited substring with Text::Balanced
by kba (Sexton) on Dec 25, 2008 at 23:05 UTC | |
|
Re: Extracting multiple-asterisk-delimited substring with Text::Balanced
by bruno (Friar) on Dec 26, 2008 at 04:07 UTC | |
by kba (Sexton) on Dec 26, 2008 at 10:45 UTC | |
|
Re: Extracting multiple-asterisk-delimited substring with Text::Balanced
by Anonymous Monk on Dec 25, 2008 at 23:08 UTC | |
by kba (Sexton) on Dec 25, 2008 at 23:27 UTC |