문제

Im trying to create regular expression for preg_replace in php with

Input:    this us * action (if) * fsfsffs

Output: <b id="action"> * action (if) * </b> 

So far I'm here,

$text = "    this us * action (if) * fsfsffs"
preg_replace( '#^(\s*)(\*)([^<>\n]+)(\*)(\s*)$#m', '$1<b id="$3">$2 $3 $4</b>$5', $text );

Output for same i get is,

<b id=" action (if) ">* action (if) *</b>
도움이 되었습니까?

해결책

Something like this should work:

preg_replace('#\*\s+([a-z]+)\s+\(([a-z]+)\)\s+\*#', '<b id="$1">* $1 ($2) *</b>', $input);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top