【发布时间】: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
我怎样才能去掉圆括号、方括号、花括号和里面的字?
[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
要么简单地通过alternatingbetween each设置可能发生的,并在内部使用negated class。
(?:([^)(]*)|[[^][]*]|{[^}{]*})s*
See this regex101 demo 或 PHP demo at tio.run
或者甚至通过使用unicode categories(需要均匀平衡的括号而不是嵌套)。
p{Ps}.*?p{Pe}s*
p{Ps}任何一种左括号
p{Pe}任何一种右括号
.*? any amount any character (lazy)s* 匹配任意数量的 whitespace
Regex101 demo 或另一个PHP demo at tio.run(使用s flag 使点匹配换行符)
【讨论】: