I want to match characters other than those enclosed in parentheses `[]`

Asked 2 years ago, Updated 2 years ago, 86 views

I want to match characters other than those enclosed in parentheses [], but I don't know.

Aiueo [Dark] Kakikukeko [Fuga]

↓ String to match

  • Aiueo
  • Kakikakeko

regular-expression

2022-09-30 17:36

3 Answers

I think you can do it if you use the look ahead.
If the part (A) to be matched is [^\[\]]+, and the part (B) not to be matched is \[^\[\]+\], then the way to look ahead is A(?=B), that is, [^\[\]+(?=\[^\[[\[\]]+\]).If you combine this with the pattern A$=[^\[\]]+$ that matches the end (or the whole)

([^\[\]]+(?=\[[^\[\]]+\])|[^\[\]]+$)

will be


2022-09-30 17:36

↓ String to match

Oh, my God. Kakikakeko

If you want to match only these two patterns, simply

(Aye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye

is acceptable (for POSIX regular expressions).

Regular expressions may vary slightly depending on the language, so
If possible, please specify the programming language you want to use when you ask questions. would be a good idea.


2022-09-30 17:36

"Ho"
"Gee"
"Huh"

is "

if you wish to exclude [^Blowing] +

The specific match and mismatch conditions are not clear in the question, so
I think it's very difficult to answer.


2022-09-30 17:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.