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+(?[A-Z0-9\\-]+)"),
"InvoiceNumber");
In this case as a value “INV-3337” string is extracted.