【问题标题】:How to preg_replace all digits except specific numbers?如何preg_replace除特定数字以外的所有数字?
【发布时间】:2022-06-29 22:49:47
【问题描述】:

有必要清除除英文字母、空格和特定数字之外的所有字符串(例如,字符串中应保留 18、19、20)。

请帮助我使用正则表达式 /([^a-zA-Z\s])/ 以保留指定的数字

【问题讨论】:

    标签: regex preg-replace


    【解决方案1】:

    例如,您可以列出要保留在单词边界之间的数字,然后使用 SKIP FAIL:

    \b(?:1[89]|20)\b(*SKIP)(*F)|[^a-zA-Z\s]+
    

    Rgex demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多