【问题标题】:How to remove parenthesis, brackets, braces and words inside?如何去除括号、括号、大括号和里面的单词?
【发布时间】:2022-12-17 09:25:35
【问题描述】:

我怎样才能去掉圆括号、方括号、花括号和里面的字?

  • [art name] book name [English] {some text} (some text)
  • [art name] book name2 [English] {some text} (some text)

我希望最终结果是书名。我使用 PHP 和preg_replace

【问题讨论】:

    标签: php regex preg-replace


    【解决方案1】:

    要么简单地通过alternatingbetween each设置可能发生的,并在内部使用negated class

    (?:([^)(]*)|[[^][]*]|{[^}{]*})s*
    

    See this regex101 demoPHP demo at tio.run


    或者甚至通过使用unicode categories(需要均匀平衡的括号而不是嵌套)。

    p{Ps}.*?p{Pe}s*
    

    Regex101 demo 或另一个PHP demo at tio.run(使用s flag 使点匹配换行符)


    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-12
      • 1970-01-01
      • 2021-01-11
      • 2014-10-30
      • 2011-09-26
      • 1970-01-01
      相关资源
      最近更新 更多