Package com.norconex.commons.lang.text

# Class RegexFieldValueExtractor

java.lang.Object
com.norconex.commons.lang.text.RegexFieldValueExtractor

public class RegexFieldValueExtractor extends Object

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.

Since:
  2.0.0 (moved from Norconex Importer RegexKeyValueExtractor)

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final RegexFieldValueExtractor[]`
  `EMPTY_ARRAY`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RegexFieldValueExtractor()`
  `RegexFieldValueExtractor(Regex regex)`
  `RegexFieldValueExtractor(Regex regex, int fieldGroup, int valueGroup)`
  `RegexFieldValueExtractor(Regex regex, String field)`
  `RegexFieldValueExtractor(Regex regex, String field, int valueGroup)`
  `RegexFieldValueExtractor(String pattern)`
  `RegexFieldValueExtractor(String pattern, int fieldGroup, int valueGroup)`
  `RegexFieldValueExtractor(String pattern, String field)`
  `RegexFieldValueExtractor(String pattern, String field, int valueGroup)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected boolean`
  `canEqual(Object other)`
  `boolean`
  `equals(Object o)`
  `void`
  `extractFieldValues(Properties dest, CharSequence text)`
  `static void`
  `extractFieldValues(Properties dest, CharSequence text, RegexFieldValueExtractor... extractors)`
  `static void`
  `extractFieldValues(Properties dest, CharSequence text, List<RegexFieldValueExtractor> extractors)`
  `Properties`
  `extractFieldValues(CharSequence text)`
  `static Properties`
  `extractFieldValues(CharSequence text, RegexFieldValueExtractor... extractors)`
  `static Properties`
  `extractFieldValues(CharSequence text, List<RegexFieldValueExtractor> extractors)`
  `int`
  `getFieldGroup()`
  `PropertySetter`
  `getOnSet()`
  Gets the property setter to use when a value is set.
  `Regex`
  `getRegex()`
  `String`
  `getToField()`
  `int`
  `getValueGroup()`
  `int`
  `hashCode()`
  `RegexFieldValueExtractor`
  `setFieldGroup(int fieldGroup)`
  `RegexFieldValueExtractor`
  `setOnSet(PropertySetter onSet)`
  Sets the property setter to use when a value is set.
  `RegexFieldValueExtractor`
  `setRegex(Regex regex)`
  `RegexFieldValueExtractor`
  `setToField(String field)`
  `RegexFieldValueExtractor`
  `setValueGroup(int valueGroup)`
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### EMPTY_ARRAY

    public static final RegexFieldValueExtractor[] EMPTY_ARRAY

- ## Constructor Details

  - ### RegexFieldValueExtractor

    public RegexFieldValueExtractor()

  - ### RegexFieldValueExtractor

    public RegexFieldValueExtractor(String pattern)

  - ### RegexFieldValueExtractor

    public RegexFieldValueExtractor(String pattern, String field)

  - ### RegexFieldValueExtractor

    public RegexFieldValueExtractor(String pattern, String field, int valueGroup)

  - ### RegexFieldValueExtractor

    public RegexFieldValueExtractor(String pattern, int fieldGroup, int valueGroup)

  - ### RegexFieldValueExtractor

    public RegexFieldValueExtractor(Regex regex)

  - ### RegexFieldValueExtractor

    public RegexFieldValueExtractor(Regex regex, String field)

  - ### RegexFieldValueExtractor

    public RegexFieldValueExtractor(Regex regex, String field, int valueGroup)

  - ### RegexFieldValueExtractor

    public RegexFieldValueExtractor(Regex regex, int fieldGroup, int valueGroup)

- ## Method Details

  - ### getRegex

    public Regex getRegex()

  - ### setRegex

    public RegexFieldValueExtractor setRegex(Regex regex)

  - ### getFieldGroup

    public int getFieldGroup()

  - ### setFieldGroup

    public RegexFieldValueExtractor setFieldGroup(int fieldGroup)

  - ### getValueGroup

    public int getValueGroup()

  - ### setValueGroup

    public RegexFieldValueExtractor setValueGroup(int valueGroup)

  - ### getToField

    public String getToField()

  - ### setToField

    public RegexFieldValueExtractor setToField(String field)

  - ### getOnSet

    public PropertySetter getOnSet()
    Gets the property setter to use when a value is set.
    Returns:
      property setter
    Since:
      3.0.0

  - ### setOnSet

    public RegexFieldValueExtractor setOnSet(PropertySetter onSet)
    Sets the property setter to use when a value is set.
    Parameters:
      `onSet` - property setter
    Returns:
      this instance
    Since:
      3.0.0

  - ### extractFieldValues

    public void extractFieldValues(Properties dest, CharSequence text)

  - ### extractFieldValues

    public Properties extractFieldValues(CharSequence text)

  - ### extractFieldValues

    public static void extractFieldValues(Properties dest, CharSequence text, List<RegexFieldValueExtractor> extractors)

  - ### extractFieldValues

    public static Properties extractFieldValues(CharSequence text, List<RegexFieldValueExtractor> extractors)

  - ### extractFieldValues

    public static void extractFieldValues(Properties dest, CharSequence text, RegexFieldValueExtractor... extractors)

  - ### extractFieldValues

    public static Properties extractFieldValues(CharSequence text, RegexFieldValueExtractor... extractors)

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### canEqual

    protected boolean canEqual(Object other)

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`