javascript - 匹配没有至少两个分号的左括号和右括号

标签 javascript regex

我有这样的文字:

[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

但它不起作用。

最佳答案

只是一个小改动。您还需要在否定字符类中包括 \]; 因为 [^;] 也应该匹配 ],所以它应该超过右括号]

\[((?![^;\]]*;[^;\]]*;[^\]]*\])[^\]]+)\]

DEMO

关于javascript - 匹配没有至少两个分号的左括号和右括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36938050/

相关文章:

javascript - 如何选择相关元素jquery的prev no

JavaScript : problem with regular expression

javascript - "Undefined is not a function"调用 Backbone 集合的获取函数时出错

regex - 将多行文本括在特定正则表达式捕获组的引号内

javascript - 在 JavaScript 中的单个多行字符串中的换行符之前 trim 尾随空格

php - preg_replace 双空格到行首的制表符 (\t)

javascript - 如何传递dicom文件在基石库中的路径并显示它?

regex - 有没有办法计算 Perl 正则表达式匹配的次数?

java - Struts2 正则表达式配置

javascript - 获取 json 意外 token