希望使用 preg_replace 从我的字符串中删除字符

最佳结果

我有正确的功能,只是没有找到正确的正则表达式模式来从字符串中删除 (ID:999999)。此 ID 值各不相同,但都是数字。我喜欢删除包括括号在内的所有内容。

$string = "This is the value I would like removed. (ID:17937)";
$string = preg_replace('#(ID:['0-9']?)#si', "", $string);

正则表达式不再是强项!并且需要这方面的帮助。

米可

试试这个:

$string = preg_replace('# \(ID:[0-9]+\)#si', "", $string);

您需要使用反斜杠转义括号\
您不应在数字范围内使用引号。
您应该使用+(一个或多个)而不是?(零或一个)。
您可以在开头添加一个空格,以避免在结果字符串的末尾有一个空格。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用preg_replace从字符串中删除Â

来自分类Dev

使用 preg_replace 转换字符串中的 URL

来自分类Dev

尝试使用preg_replace从图像src的字符串中删除多余的“ -1”

来自分类Dev

使用preg_replace转换字符串

来自分类Dev

使用preg_replace“更新”搜索到的字符串

来自分类Dev

使用preg_replace模式清理字符串

来自分类Dev

在 preg_replace 中使用子字符串

来自分类Dev

使用preg_replace删除字符串。还有其他选择吗?

来自分类Dev

使用preg_replace在php中的两个字符串之间删除文本

来自分类Dev

使用php preg_replace从utf-8编码的字符串中删除一些标点符号

来自分类Dev

使用preg_replace删除<script>标签

来自分类Dev

使用preg_replace删除某些内容

来自分类Dev

使用preg_replace()将URL转换为字符串中的链接

来自分类Dev

无法在大字符串上使用 preg_replace

来自分类Dev

如何使用preg_replace将子字符串替换为数组中的字符串?(PHP)

来自分类Dev

preg_replace删除特殊字符串中的内容

来自分类Dev

preg_replace函数从字符串中删除空格

来自分类Dev

如何使用preg_replace在输出字符串中保留连字符

来自分类Dev

使用preg_replace更改字符串名称,删除空格和点,但是允许点扩展

来自分类Dev

使用preg_replace()和regex将大写字符串替换为小写

来自分类Dev

使用preg_replace()获取字符串的一部分

来自分类Dev

在.com或.net或.org之后使用preg_replace()截断字符串

来自分类Dev

如何使用不带引号的 preg_replace 连接字符串

来自分类Dev

如何使用preg_replace()从URL中删除重复的值

来自分类Dev

使用preg_replace时,从关键字中删除$

来自分类Dev

正则表达式preg_replace使用img属性在字符串中查找图像

来自分类Dev

使用preg_replace通过ID删除div

来自分类Dev

当我使用'preg_replace()'时,'method'属性消失了

来自分类Dev

删除unicode字符,但使用preg_replace保留所有特殊和英文字符

Related 相关文章

  1. 1

    使用preg_replace从字符串中删除Â

  2. 2

    使用 preg_replace 转换字符串中的 URL

  3. 3

    尝试使用preg_replace从图像src的字符串中删除多余的“ -1”

  4. 4

    使用preg_replace转换字符串

  5. 5

    使用preg_replace“更新”搜索到的字符串

  6. 6

    使用preg_replace模式清理字符串

  7. 7

    在 preg_replace 中使用子字符串

  8. 8

    使用preg_replace删除字符串。还有其他选择吗?

  9. 9

    使用preg_replace在php中的两个字符串之间删除文本

  10. 10

    使用php preg_replace从utf-8编码的字符串中删除一些标点符号

  11. 11

    使用preg_replace删除<script>标签

  12. 12

    使用preg_replace删除某些内容

  13. 13

    使用preg_replace()将URL转换为字符串中的链接

  14. 14

    无法在大字符串上使用 preg_replace

  15. 15

    如何使用preg_replace将子字符串替换为数组中的字符串?(PHP)

  16. 16

    preg_replace删除特殊字符串中的内容

  17. 17

    preg_replace函数从字符串中删除空格

  18. 18

    如何使用preg_replace在输出字符串中保留连字符

  19. 19

    使用preg_replace更改字符串名称,删除空格和点,但是允许点扩展

  20. 20

    使用preg_replace()和regex将大写字符串替换为小写

  21. 21

    使用preg_replace()获取字符串的一部分

  22. 22

    在.com或.net或.org之后使用preg_replace()截断字符串

  23. 23

    如何使用不带引号的 preg_replace 连接字符串

  24. 24

    如何使用preg_replace()从URL中删除重复的值

  25. 25

    使用preg_replace时,从关键字中删除$

  26. 26

    正则表达式preg_replace使用img属性在字符串中查找图像

  27. 27

    使用preg_replace通过ID删除div

  28. 28

    当我使用'preg_replace()'时,'method'属性消失了

  29. 29

    删除unicode字符,但使用preg_replace保留所有特殊和英文字符

热门标签

归档