question: public static Pair < String , String > parseTitleAndDateInBrackets ( String title ) { if ( title == null ) return new Pair < > ( null , null ) ; Pattern p = Pattern . compile ( "(.*)\\s+\\(?([0-9]{4})\\)?" , Pattern . CASE_INSENSITIVE ) ; Matcher m = p . matcher ( title ) ; if ( m . find ( ) ) { return new Pair < > ( m . group ( 1 ) , m . group ( 2 ) ) ; } return new Pair < > ( title , null ) ; }
target:  Parses titles if they are in the form Title (Year). The first element is the title, and the second element is the date, both can be null. If the matcher fails to find the pattern, then the passed in title is set as the first element, which is the title.