public void addPatternFromReader ( Reader r ) throws IOException { BufferedReader br = new BufferedReader ( r ) ; String line ; // We dont want \n and commented line Pattern MY_PATTERN = Pattern . compile ( "^([A-z0-9_]+)([~]?)\\s+(.*)$" ) ; while ( ( line = br . readLine ( ) ) != null ) { Matcher m = MY_PATTERN . matcher ( line ) ; if ( m . matches ( ) ) { if ( m . group ( 2 ) . length ( ) > 0 ) { // process line as simple template this . addPattern ( m . group ( 1 ) , simpleTemplateToRegEx ( m . group ( 3 ) ) ) ; } else { this . addPattern ( m . group ( 1 ) , m . group ( 3 ) ) ; } } } br . close ( ) ; }
Add patterns from a reader