Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^4: Replace newlines only if not inside braces

by LanX (Chancellor)
on Feb 11, 2013 at 20:15 UTC ( #1018234=note: print w/replies, xml ) Need Help??

in reply to Re^3: Replace newlines only if not inside braces
in thread Replace newlines only if not inside braces

$data =~ s<(?:{{.*?}}|[^\n])*\K\n>{<br>\n}gs;

I think (didn't test it) that the * is two greedy, better *?.

Cheers Rolf

Replies are listed 'Best First'.
Re^5: Replace newlines only if not inside braces
by trizen (Hermit) on Feb 11, 2013 at 21:47 UTC
    Nope. It doesn't matter. The group doesn't match a single newline, so it can be greedy. It will try to match either the brackets block or any other character which is not a newline. If it succeeds, then tries again to match the block or a non-newline character. If it fails, it will match the newline character (\n) and makes the replace.

    Using the non-greedy quantifier, will do the same thing, but a little bit slower because it needs, unnecessary, to look ahead after each repetition (theoretically).

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2016-10-22 16:50 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (297 votes). Check out past polls.