public static String regexpExtract ( String str , String regex , int extractIndex ) { if ( extractIndex < 0 ) { return null ; } try { Matcher m = REGEXP_PATTERN_CACHE . get ( regex ) . matcher ( str ) ; if ( m . find ( ) ) { MatchResult mr = m . toMatchResult ( ) ; return mr . group ( extractIndex ) ; } return null ; } catch ( Exception e ) { LOG . error ( String . format ( "Exception in regexpExtract('%s', '%s', '%d')" , str , regex , extractIndex ) , e ) ; return null ; } }
Returns a string extracted with a specified regular expression and a regex match group index .