Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
たとえば、角かっこで囲まれたテキストを選択できるようにしたいと思います。
たとえば、次のテキストがあります
This is a (sample (or, may be, not)) text, which I write in a browser(with keyboard)
どの正規表現パターンを使用する必要がありますか?
(sample (or, may be, not))
と
(with keyboard)
ネストされた角かっこはいくつでも使用できますか?
正規表現の既知の制限の1つは、正規表現がネストを処理できないことです。たとえば
a nbnを正規表現と一致させることはできません 。
適切に括弧で囲まれた文字列は、正規表現とも一致しません。
通常、ある種の再帰的な文脈自由文法の実装を行います
(?<Depth>\() ( (?(Depth)([^\(\)]+)) | (?<Depth>\() | (?<-Depth>\)) )* (?(Depth)(?!))
私にとってはうまくいきます。