2

私はjavascriptでの正規表現が初めてです。以下のような文字列があります。

" and something here ( something else here and (something here and something here) something elseまたはsomething else) asdf (またはasdfas) and something hereまたはsomething here ( something else here and something else or something else)"

上記の文字列から、次のルールに基づいてテキストのグループをキャプチャしようとしています。

  • orで始まり"and"or"or"で終わる行をキャプチャする"or""and"
  • キャプチャされた行には、多くの括弧を含めることができます。
  • 演算子"or"または"and"が括弧内にある場合、それらを無視します

上記の文字列から、以下に示すような結果のグループが期待されます

  • and something here ( something else here and (something here and something here) something elseまたはsomething else) asdf (またはasdfas)
  • そしてここに何か
  • またはここに何か(ここに何か他のものと何か他のものまたは何か他のもの)

私は多くの正規表現を試しましたが、私が望むものに近いものは次のとおりです。

(and|or)\s.((?!(and|or)).)*

正規表現以外のソリューションでも問題ありません。

4

2 に答える 2