private void processRegexRule ( final String parsed_value ) { if ( rule . getCompiledRegex ( ) == null ) { throw new IllegalArgumentException ( "Regex was null for rule: " + rule ) ; } final Matcher matcher = rule . getCompiledRegex ( ) . matcher ( parsed_value ) ; if ( matcher . find ( ) ) { // The first group is always the full string, so we need to increment // by one to fetch the proper group if ( matcher . groupCount ( ) >= rule . getRegexGroupIdx ( ) + 1 ) { final String extracted = matcher . group ( rule . getRegexGroupIdx ( ) + 1 ) ; if ( extracted == null || extracted . isEmpty ( ) ) { // can't use empty values as a branch/leaf name testMessage ( "Extracted value for rule " + rule + " was null or empty" ) ; } else { // found a branch or leaf! setCurrentName ( parsed_value , extracted ) ; } } else { // the group index was out of range testMessage ( "Regex group index [" + rule . getRegexGroupIdx ( ) + "] for rule " + rule + " was out of bounds [" + matcher . groupCount ( ) + "]" ) ; } } }
Runs the parsed string through a regex and attempts to extract a value from the specified group index . Group indexes start at 0 . If the regex was not matched or an extracted value for the requested group did not exist then the processor returns and the rule will be considered a no - match .