![](/img/trans.png)
[英]How to handle/highlight/mark multiple brackets (),{},[], and «» in regular expression using regex101 PHP
[英]How to mark word or sentence in single brackets {,(,[,» using regular expression in regex101 tool php
我试图用单括号标记单词或句子,这个括号可以放在单词或句子的左侧或右侧和中间。
regex101 工具中的其他单词或句子不应被打扰https://regex101.com/r/9PCacf/14下面的示例
像这样的东西(如果你可以简单地找到错误的线路)
^(?: # Start of line and alternation group
.*[[{(«][^\]})»\n]* # un-closed
|
[^[{(«\n]*[\]})»].* # never opened
|
.*\w[[{(«].* # opened mid-word
|
.*[\]})»]\w.* # closed mid-word
)$ # End of line and alternation group
编辑:
要成对测试不同的括号类型,请使用
^(?:\([^)\n]*|[^(\n]*\).*|\[[^]\n]*|[^[\n]*\].*|{[^}\n]*|[^{\n]*}.*|«[^»\n]*|[^«\n]*».*|.*\w[[{(«].*|.*[\]})»]\w.*)$
更难阅读(更长),但对您来说可能更准确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.