该字符串将看起来像这样:如何将字符串转换为字符串数组中的Java(忽略空格和括号)
String temp = "IF (COND_ITION) (ACT_ION)";
// Only has one whitespace in either side of the parentheses
或
String temp = " IF (COND_ITION) (ACT_ION) ";
// Have more irrelevant whitespace in the String
// But no whitespace in condition or action
我希望能得到一个新的String数组,包含三个要素,忽略括号:
String[] tempArray;
tempArray[0] = IF;
tempArray[1] = COND_ITION;
tempArray[2] = ACT_ION;
我试图使用String.split(regex)方法,但我没有知道如何实现正则表达式。
可能重复的[如何分割字符串与任何空白字符作为分隔符?](http://stackoverflow.com/questions/225337/how-do-i-split-a-string-with-任何-空格字符-AS-分隔符),然后你可以在'\('和'\)'作为额外的东西添加删除(除非这些括号是一个例子)。 – birryree
等等,现在我想你的第二个例子(其中有不相干的空白字符串中)。你能否给我们提供一个你想要分割的字符串类型的更好的例子?条件和行动中是否有空白?括号会在那里吗? – birryree
@birryree没有空格的情况和行为,并没有括号 –