2023:Pattern Match (Value Extractor)

From Grooper Wiki
Revision as of 17:24, 27 January 2023 by Dsmith (talk | contribs) (→‎How To)
WIP

This article is a work-in-progress or created as a placeholder for testing purposes. This article is subject to change and/or expansion. It may be incomplete, inaccurate, or stop abruptly.

This tag will be removed upon draft completion.

Pattern Match is an Extractor Type found in Grooper. This extractor primarily uses regular expression (regex) for general data extraction.

About

Pattern Match is one of the most commonly used extractors for general data. As per its name, it extracts data from a document matching a regex pattern entered into the Value Pattern.

This extractor is useful when you want to extract text data matching a particular pattern across a document, such as dates or social security numbers. For example, the format MM/DD/YYYY can be matched with the regex pattern: \d{2}/\d{2}/\d{4}.

For more information on regex, click the following link: RegexOne

How To

Pattern Match can be configured on both Data Type and Value Reader objects.

Configuring by Object Type

Configuring on a Value Reader

  1. Create or select your Value Reader.
    • Note the three tabs, "Value Reader", "Tester", and "Advanced".
  2. Select the "Value Reader" tab.
  3. Select the drop-down icon on the far right to the far right of the Extractor property.

  1. On the drop-down menu, select Pattern Match.

  1. Click the "Tester" tab.
  2. In the Value Pattern box, enter the regex pattern for the text you wish to extract.

  1. Matched data will be highlighted in green and show up in the "Values" panel beneath the Document Viewer.

Configuring on a Data Type

The Data Type is a little more involved when picking out Pattern Match.

  1. Create or select your Data Type.
  2. Select the drop-down icon to the far right of Local Extractor.

  1. Select Pattern Match from the dropdown menu.
  2. Select the ellipses to the far right of the Local Extractor.

This will bring up the Extractor Editor window

  1. Enter a pattern for the text you would like to extract.
  2. Once you've entered your pattern, and are satisfied with the results, click "OK".

  1. Just like with the Value Reader, matched data will be highlighted in green and appear in the "Values" panel beneath the Document Viewer.

Regex Examples for Pattern Match

Dates

Take note of the format of the date(s) on the document. The document here has dates in both the MM/DD/YYYY and MM/DD/YY format. Thus, we will write a regex pattern that will extract both dates.

  1. Enter the regex pattern to extract the date.
  2. First, enter
    • \d{2}/\d{2}/\d{4}
  3. Notice that only the first date was returned.

  1. Now try:
    • \d{2}/\d{2}/\d{2}
  2. Kind of picks up both, except that the last two digits in the year of the first date aren't returned. So, this regex pattern won't work either.

  1. So, how are we going to return both dates completely? Keep in mind that you can dictate a range of values within the curly braces. Hence:
    • \d{2}/\d{2}/\d{2,4}
      • \d{2,4} tells Grooper to look for anywhere from two to four digits for the year. Since YY and YYYY fall within the range set, the regex pattern will extract them.
  2. Notice that both dates are now being returned in full.

Currency

For this example, the pattern provided will match all currency data listed.

  1. Note the amount listed, as well as any cent amounts and dollar signs being given.
  2. If dollar signs are given, code them out by preceding them with a backslash: \$.
    • $ by itself represents the end of a string in regex.
  3. When writing the pattern for currencies, look for the largest and smallest amounts provided, as this will determine the range for the placeholders.
  4. To extract the first three data instances, enter the following pattern:
    • [$]\d{1,3}\.\d{2}

  1. To extract the remaining three data instances, you will need to account for the thousandths, ten-thousandths, and hundred-thousandths place; thus, the pattern will be the same as it was for the tens/hundreds/thousandths place: \d{1,3}
  2. Your regex pattern should look like this:
    • \$\d{1,3},\d{1,3}\.\d{2}
    • Note that while the last three pieces of date are matched, the first three are no longer being picked up.

  1. Thus, to return all data, add parenthesis around \d{1,3}, and follow with a question mark:
    • \$\d{1,3}(,\d{3})?\.\d{2}
    • If you're unsure of how large your currency amounts will be, you can substitute the question mark ? with a star * character.
      • \$\d{1,3}(,\d{3})*\.\d{2}

Social Security Numbers (SSN)/Employer Identification Numbers (EIN)

  1. Note the format of the SSN/EIN
    • SSNs will be ###-##-####, EINs are ##-#######
  2. Enter the pattern that will match the data you wish to extract.
  3. SSNs will be:
    • \d{3}-\d{2}-\d{4}

  1. EINs will be:
    • \d{2}-\d{7}.

Prefix and Suffix Patterns

Prefix and Suffix Patterns act as anchors to which you can tether the data you wish to extract. As one would expect, a Prefix Pattern matches what comes before your text matched by regex pattern, a Suffix Pattern is concerned with what comes after.

For example, let's say that you want to extract data on its own line, like the title of a section. While you can enter just the title, you might get false positives if the word(s) that make up the title appear anywhere else on the document. Thus, your Prefix and Suffix Patterns will be:

Prefix Pattern:[\n\t]

Suffix Pattern:[\r\t]

See Also: