我希望能够匹配零个或多个字符列表和/或匹配零个或多个字符串列表。
示例: Here is my 12345 test string 123456.
目标: Here is my 45 test string .
所以我希望删除1
,2
和3
,但只有456
才会删除它。
我尝试了/[123]+456+/gs
之类的东西,但我知道这是错误的。
感谢任何帮助。
答案 0 :(得分:1)
/[123]|456/
可能就是您想要的。
答案 1 :(得分:1)
代码:
$str = "Here is my 12345 test string 123456.";
$res = preg_replace('/[123]|456/','',$str);
echo $res;
输出:
Here is my 45 test string .
答案 2 :(得分:0)
对于javascript,这有效:
var oldString = 'Here is my 12345 test string 123456.';
var newString = oldString.replace(/[123](456)?/g, '');