使用 Preg_replace 时出现问题

Issue in using Preg_replace

我想从单词右边替换"ing",但是下面的代码也在替换其他字符。

$temp = "gameing"; //incorrect spellings for test//
$temp = preg_replace('/(\w)ing\b/','',$temp);
echo $temp;

给出输出 "gam",而不是 game

如果您需要"ing"之前的字符,您可以将其替换为:

<?php
$temp = "gameing";
$temp = preg_replace('/(\w)ing\b/','',$temp);
//-> game
echo $temp;