protected List < String > filter ( List < String > lines , String regexp , boolean invert ) { List < String > result ; Pattern pattern ; result = new ArrayList <> ( ) ; pattern = Pattern . compile ( regexp ) ; for ( String line : lines ) { if ( invert ) { if ( ! pattern . matcher ( line ) . matches ( ) ) result . add ( line ) ; } else { if ( pattern . matcher ( line ) . matches ( ) ) result . add ( line ) ; } } return result ; }
Filters the list of strings with a regular expression .