Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Community Library
How to contribute
x
Search regex
Open Workspace
PCRE (Legacy)
Match
Created 2015-08-26 17:22
1
Regular Expression
/
(
\[
(?:
[^
[
\]
]
*?
)
\]
\s
*?
(?=
\[
)
)
|
(
\[
(?:
[^
[
\]
]
*?
)
\]
(?!
\s
*
[
\|
&
]
\s
*
.
)
)
|
(?:
\[
[^
[
\]
]
*?
]
)
|
(
[^
&
\|
\s
]
+
)
\s
+
(?=
[^
&
\|
\s
]
+
)
/
g
Description
/**
this regex should match most cases where the user forgets to put an operator somewhere and add an OR, it still
does not handle nested square brackets but those are invalid anyways
this page has an explanation
https://regex101.com/r/fF7wO1/2
the way this regex grabs conflicting matches is by oring different cases together in the order we want to grab them in
the first case is for a set of brackets immediately followed by an opening bracket (seperate them with an or)
the second case is for a set of brackets immediately followed by any non operator character (seperate with an or)
the third case is for a set of brackets followed by an operator (do nothing)
the final case is for two words outside of brackets seperated by a space (fill space with an or)
@type {RegExp} */
Submitted by
warnock