How to remove anything in a string after “-”?

后端 未结 7 951
迷失自我
迷失自我 2020-12-23 15:05

This is the example of my string.

$x = \"John Chio - Guy\";
$y = \"Kelly Chua - Woman\";

I need the pattern for the reg replace.

         


        
7条回答
  •  佛祖请我去吃肉
    2020-12-23 15:29

    I hope these patterns will help you =]

    $pattern1='/.+(?=\s-)/'       //This will match the string before the " -";
    $pattern2='/(?<=\s-\s).+/'    //This will match the string after the "- ";
    

提交回复
热议问题