Extract overlapping matches using split

前端 未结 3 1621
广开言路
广开言路 2021-01-06 16:22

How can I extract overlapping matches from an input using String.split()?

For example, if trying to find matches to \"aba\":



        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-06 17:03

    This is not a correct use of split(). From the javadocs:

    Splits this string around matches of the given regular expression.

    Seems to me that you are not trying to split the string but to find all matches of your regular expression in the string. For this you would have to use a Matcher, and some extra code that loops on the Matcher to find all matches and then creates the array.

提交回复
热议问题