I'd like to be able to开发者_开发百科 match zero or more of a list of characters AND/OR match zero or more of a list of strings.
Example: Here is my 12345 test string 123456.
Target: Here is my 45 test string .
So I wish to remove 1, 2, and 3, but only remove 456 if it's a whole string.
I have tried something like /[123]+456+/gs but I know this is wrong.
Any help is appreciated.
/[123]|456/ may be what you want.
Code:
$str = "Here is my 12345 test string 123456.";
$res = preg_replace('/[123]|456/','',$str);
echo $res;
Output:
Here is my 45 test string .
For javascript, this works:
var oldString = 'Here is my 12345 test string 123456.';
var newString = oldString.replace(/[123](456)?/g, '');
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论