文字列からコメントを削除する必要があります。コメントは引用符を使用して指定します。例えば:
removeComments("1+4 'sum'").equals("1+4 ");
removeComments("this 'is not a comment").equals("this 'is not a comment");
removeComments("1+4 'sum' 'unclosed comment").equals("1+4 'unclosed comment");
引用符のインデックスを追跡しながら、文字列の文字を反復処理できますが、より簡単な解決策があるかどうかを知りたいです (おそらく正規表現ですか?)