php - 在 php 中使用正则表达式查找结果 str

标签 php regex preg-replace preg-match

我有一个输入字符串:

$str1 = "some usefull text and garbage `~#@!&^*(()}{./";
$str2 = "`~#@!&^*(()}{./";

$result = Exclude with regular expressions all symbols from str1, which are in str2.
$result = "some usefull text and garbage";

什么正则表达式会简单地删除我指定的所有符号?如何以正确的方式过滤它?谢谢!

最佳答案

你不需要正则表达式:

$clean_str = str_replace(str_split($str2), '', $str1);

您可能想要修剪结果字符串。

关于php - 在 php 中使用正则表达式查找结果 str,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8071016/

相关文章:

php - 如何在 Codeigniter 中生成此 MySQL 代码?

Python 正则表达式间距

Ruby:查找字符串中所有出现的模式,操作,然后替换

php - 在函数内部的 preg_replace 中调用函数

php - 如何删除另一个div中的唯一div标签

php - 在PHP页面上显示mysql数据库中最后添加的用户

php - 如何使用爆炸检索多个复选框值?

php - 如何正确使用facebook OAuth2?

regex - 如何使用 sed 提取以 '(' 开头的模式

php - 查找并替换可能部分位于 html 标记内的字符串