我有这样的文字:
[Unix; common] To expand special characters in a wildcarded name, or the act of so doing (the action is also called [[b;#fff;]globbing]). The Unix conventions for filename wildcarding have become sufficiently pervasive that many hackers use some of them in written English, especially in email or news on technical topics. Those commonly encountered include the following:Some examples: [[i;;]He said his name was [KC]arl] (expresses ambiguity). [[i;;]I don't read talk.politics.*] (any of the talk.politics subgroups on [[bu;#fff;;jargon]Usenet]). Other examples are given under the entry for [[bu;#fff;;jargon]X]. Note that glob patterns are similar, but not identical, to those used in [[bu;#fff;;jargon]regexp]s.Historical note: The jargon usage derives from glob, the name of a subprogram that expanded wildcards in archaic pre-Bourne versions of the Unix shell.
我想替换 [KC]
和 [Unix; common]
由 \[KC\]
和 \[Unix;常见\]
我试过这个正则表达式:
/\[(?![^;]*;[^;]*;[^\]]*\])[^\]]+\]/g
但它不起作用。
最佳答案
只是一个小改动。您还需要在否定字符类中包括 \]
和 ;
因为 [^;]
也应该匹配 ]
,所以它应该超过右括号]
。
\[((?![^;\]]*;[^;\]]*;[^\]]*\])[^\]]+)\]
关于javascript - 匹配没有至少两个分号的左括号和右括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36938050/