gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 16:06:43 25 4
gpt4 key购买 nike

我有这样的文字:

[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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com