Java String.split() Regex

后端 未结 6 592
南笙
南笙 2020-11-27 16:23

I have a string:

String str = \"a + b - c * d / e < f > g >= h <= i == j\";

I want to split the string on all of the operators

6条回答
  •  借酒劲吻你
    2020-11-27 17:01

    Can you invert your regex so split by the non operation characters?

    String ops[] = string.split("[a-z]")
    // ops == [+, -, *, /, <, >, >=, <=, == ]   
    

    This obviously doesn't return the variables in the array. Maybe you can interleave two splits (one by the operators, one by the variables)

提交回复
热议问题