Skip to content Skip to sidebar Skip to footer

Auto

Regex - Fix Needed

I have this function (which I found somewhere in Stackoverflow) to automatically add

tags in a string for the output. function autop ($string) { // Define block tags

Solution 1:

I am not sure if you will be happy with your solution all the way, but you should get what you are trying to do with this (watch the added ?= in the 5th line):

$pattern = <<<PATTERN
/
(\A|\\n\\n)(?!$tags) # Start of string or two linebreaks or anything but a block tag
(.+?) # Just about anything
(?=\Z|\\n\\n) # End of string or two line breaks
/isex
PATTERN;

Without this the previous boundary \Z would consume the next \A and therefore this would not match anymore. And of course remove the double preg_replace.

Hope this helps.

Post a Comment for "Auto

Regex - Fix Needed"