com.groupdocs.parser.templates

Class TemplateRegexPosition



  • public class TemplateRegexPosition
    extends TemplatePosition
    Provides a template field position which uses the regular expression.

    The following example shows the situation if the document contains "Invoice Number INV-12345" then template field can be defined in the following way:

    // Create a regex template field with "InvoiceNumber" name
     TemplateField templateField = new TemplateField(
         new TemplateRegexPosition("Invoice Number\\s+[A-Z0-9\\-]+"),
         "InvoiceNumber");
     

    In this case as a value the entire string is extracted. To extract only a part of the string the regular expression group "value" is used:

    // Create a regex template field with "InvoiceNumber" name with "value" group
     TemplateField templateField = new TemplateField(
         new TemplateRegexPosition("Invoice Number\\s+(?<value>[A-Z0-9\\-]+)"),
         "InvoiceNumber");

    In this case as a value "INV-3337" string is extracted.

    • Constructor Detail

      • TemplateRegexPosition

        public TemplateRegexPosition(String expression)
        Initializes a new instance of the TemplateRegexPosition class.
        Parameters:
        expression - The regular expression.
      • TemplateRegexPosition

        public TemplateRegexPosition(String expression,
                             boolean matchCase)
        Initializes a new instance of the TemplateRegexPosition class.
        Parameters:
        expression - The regular expression.
        matchCase - The value that indicates whether a text case isn't ignored.
    • Method Detail

      • getExpression

        public String getExpression()
        Gets the regular expression.
        Returns:
        A string that represents the regular expression.
      • isMatchCase

        public boolean isMatchCase()
        Gets the value that indicates whether a text case isn't ignored.
        Returns:
        true if a text case isn't ignored; otherwise, false.