On Thu, Jan 18, 2007 at 06:33:49PM -0800, Allen Watson wrote:
> I've never used recursive patterns. It seems like they might solve this
> problem:
>
> Given a block of five or six (or more) paragraphs of text, separated by
> blank lines (consecutive returns), preceded by an HTML <p> tag and followed
> by a </p> tag (around the entire block of text); find/replace to replace all
> the intervening double returns with "\r</p>\r</p>", thus marking all the
> return-delimited paragraphs as HTML paragraphs.
>
> I have this search pattern:
>
> (<p>)((?s).+?)(\r\r)((?s).+?)(</p>)
>
> And this replace pattern:
>
> \1\2\r</p>\r<p>\4\5
>
> When I run it, it finds and replaces the first double return; run
> repeatedly, it eventually replaces all of them, one per run.
>
> Is there a way, using recursion, to do this all in a single find/replace
> operation?
No. Recursive patterns are for matching recursive strings, such as nested
parentheses. What you need is to do a further search and replace within
the first search and replace.
Here's one way to do it in Perl:
#!perl
local $/;
$_ = <>;
s{(<p>.+?</p>)}{$x = $1; $x =~ s,\n\n,\n</p>\n<p>,g; $x}sge;
print;
__END__
Ronald
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>