私はすべての場合に機能するsolnを見つけたようです:
Enter your regex: \(.*?\)[0-9]{0,2}|[\w]+
Enter input string to search: Fe2(CH3)2O4(CH2O)(CH3)
I found the text "Fe2" starting at index 0 and ending at index 3.
I found the text "(CH3)2" starting at index 3 and ending at index 9.
I found the text "O4" starting at index 9 and ending at index 11.
I found the text "(CH2O)" starting at index 11 and ending at index 17.
I found the text "(CH3)" starting at index 17 and ending at index 22.
コードで使用される正規表現は次のとおりです。
String regEx = "\\(.*?\\)[0-9]{0,2}|[\\w]+";
つまり、「(」で始まり「)」で終わる文字列と数字を探します。それがない場合は、「Fe2」、「O4」などの文字列を検索します。