开发者

PHP Regex that matches everything after a certain character and ends with newline

开发者 https://www.devze.com 2023-03-31 22:26 出处:网络
Im having propbles doing this regex to get everything after a certain character (* in this case) and ends with a newline in PHP.

Im having propbles doing this regex to get everything after a certain character (* in this case) and ends with a newline in PHP.

I have:

texttextext
*Sometext
*othertext

texttextex

i want to be able to get "*Sometext and "*othertext" and add <b></b> to them.

Already tried with

$a = array( 
      "/\*(.*?)\n/is"
   ); 
   $b = array( 
    开发者_Go百科  "<b>$1</b>"
   );
   $texto = preg_replace($a, $b, $texto); 

but it does not work. What im doing wrong?


"/^\*(.*?)\n/im"

You just have to add ^ to match the beginning of the line. This requires the /m multiline flag.

The /s flag however was wrong there, as that allowed .* to also match linebreaks - which you do not want.

0

精彩评论

暂无评论...
验证码 换一张
取 消