Class RegexFieldValueExtractor

  • All Implemented Interfaces:
    IXMLConfigurable

    public class RegexFieldValueExtractor
    extends Object
    implements IXMLConfigurable

    Simplify extraction of field/value pairs (or "key/value") from text using regular expression. Match groups can be used to identify the fields and values. Field matching is optional and can be set explicitly instead. If both a "toField" and a "fieldGroup" are provided, the toField act as a default when no fields could be obtained from matching. At least one of "toField" or "fieldGroup" must be specified. If fieldGroup is specified without a "toField" and finds no matches, the matching of the value is ignored. If no value group is provided, it assumes the entire regex match is the value. If more than one value is extracted for a given toField, they will be available as a list.

    When initialized with a "pattern" only instead of passing or configuring a Regex instance, a default one will be created, assuming case insensitivity and dots matching any character.

    XML configuration usage:

    
    toField="(toField name)"
         fieldGroup="(toField name match group index)"
         valueGroup="(value match group index)"
         onSet="[append|prepend|replace|optional]"
         ignoreCase="[false|true]"
         ignoreDiacritic="[false|true]"
         dotAll="[false|true]"
         unixLines="[false|true]"
         literal="[false|true]"
         comments="[false|true]"
         multiline="[false|true]"
         canonEq="[false|true]"
         unicodeCase="[false|true]"
         unicodeCharacterClass="[false|true]"

    The above are configurable attributes consuming classes can expect. The actual regular expression is expected to be the tag content. Many of the available attributes on XML configuration represent the regular expression flags as defined in Pattern.

    XML usage example:

    
    <sampleConfig
        fieldGroup="1"
        valueGroup="2">
      (DocNo):(\d+)
    </sampleConfig>

    The above is configured to extract "DocNo" as the toField, and the following numeric characters will make up the value.

    Since:
    2.0.0 (moved from Norconex Importer RegexKeyValueExtractor)
    Author:
    Pascal Essiembre