Reputation: 66560
I have text like this:
[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.
and I want to replace [KC]
and [Unix; common]
by \[KC\]
and \[Unix; common\]
I've try this regex:
/\[(?![^;]*;[^;]*;[^\]]*\])[^\]]+\]/g
but it don't work.
Upvotes: 1
Views: 36
Reputation: 174736
Just a small change. You also need to include \]
along with ;
inside the negated char class because [^;]
should also match ]
, so it should exceed the closing bracket ]
.
\[((?![^;\]]*;[^;\]]*;[^\]]*\])[^\]]+)\]
Upvotes: 2