TemplateRegexPosition class

TemplateRegexPosition class

Provides a template field position which uses a regular expression.

The position extracts the entire match by default. To extract a specific capture group, include a named group value in the pattern; only the content of that group will be returned as the field value.

The TemplateRegexPosition type exposes the following members:

Constructors

Constructor Description
init Initializes a new TemplateRegexPosition with the specified regular expression.
init Initializes a new TemplateRegexPosition instance.

Properties

Property Description
expression The regular expression used to locate values.
match_case The value indicates whether text case is not ignored.

Example

from groupdocs.parser import Parser
from groupdocs.parser.templates import Template, TemplateField, TemplateRegexPosition

template = Template([
    TemplateField(
        TemplateRegexPosition(r"Invoice Number\s+(?<value>[A-Z0-9\-]+)"),
        "InvoiceNumber",
    )
])

with Parser("./invoice.pdf") as parser:
    data = parser.parse_by_template(template)
    if data:
        fields = data.get_fields_by_name("InvoiceNumber")
        if fields:
            print(f"Invoice number: {fields[0].text}")

See Also