public static List < String > getParts ( String string , final String ... regexpList ) { final List < String > parts = new ArrayList <> ( ) ; for ( final String regexp : regexpList ) { final Pattern pattern = Pattern . compile ( regexp ) ; final Matcher matcher = pattern . matcher ( string ) ; final boolean found = matcher . find ( ) ; if ( ! found ) { return new ArrayList <> ( ) ; } final String part = matcher . group ( 1 ) . trim ( ) ; parts . add ( part ) ; string = string . replaceFirst ( quote ( matcher . group ( ) ) , "" ) . trim ( ) ; } return parts ; }
Match one regexp at a time . Remove the matched part from the string trim and match next regexp on that string ...