php - Regex to find the words or sentences that enclosed with custom sign -
i need replace words or sentences , convert underline. i'm using php , find 1 reference: php regex, extract custom tags text
somehow, case covers single words not sentences. how make regex can catch enclosed ##
tag?
let input such as:
"ll lorem ipsum ##generators## on internet tend repeat predefined chunks necessary, making first true generator on internet. uses dictionary of on ##200 latin words##, combined handful of model sentence structures, generate lorem ipsum looks reasonable. generated lorem ipsum therefore ##free repetition##, injected humour, or non-characteristic words etc."
then output be:
"ll lorem ipsum ____1____ on internet tend repeat predefined chunks necessary, making first true generator on internet. uses dictionary of on ____2____, combined handful of model sentence structures, generate lorem ipsum looks reasonable. generated lorem ipsum therefore ____3____, injected humour, or non-characteristic words etc."
can me on how regex pattern?
i think regex is:
/##[^#]+##/g
$text = 'll lorem ipsum ##generators## on internet tend repeat predefined chunks necessary, making first true generator on internet. uses dictionary of on ##200 latin words##, combined handful of model sentence structures, generate lorem ipsum looks reasonable. generated lorem ipsum therefore ##free repetition##, injected humour, or non-characteristic words etc.'; preg_match_all('/##[^#]+##/', $text, $matches, preg_set_order); ($i = 0; $i < count($matches); $i++) { $text = preg_replace("/".$matches[$i][0]."/", "___".strval($i+1)."___" , $text, 1); }
Comments
Post a Comment