The StructuredStrings.fsp sample project
The search for a single-line field “Invoice number” with a similar format on all the pages is shown in the sample projectStructuredStrings.fsp (folder %public%\ABBYY\FlexiCapture\12.0\Samples\FLS\Tips and Tricks\Structured strings).
The project has four pages:
- Pages 1 and 2: The field “Invoice number” is filled in by means of a printer, and the printing quality is good.
- Page 3: The field “Invoice number” is filled in by means of a printer, but the image is noisy.
- Page 4: The image quality is good, but the field “Invoice number” is filled in by hand.
![]() | ![]() |
|---|---|
![]() | ![]() |
Describe the invoice number with a regular expression
The search for the field “Invoice number” relies on the field name. First, an element describing the search constraints of the field name is needed. In the project, this is a Static Text element named InvoiceNumberHeader with the value “InvoiceN:”. The field “Invoice number” is a single-line field. To detect it, the project uses a Character String element named NumAsRegularExpression. As the pages of the project show, the format of the field “Invoice number” can be described with the following regular expression:Add a fallback Character String element with an alphabet
The recommended solution to this problem is as follows. Create one more Character String element and name it NumAsAlphabet. Specify for it the same search constraints as for the NumAsRegularExpression element. Then group the two elements into one Group element, InvoiceNumber. However, describe the NumAsAlphabet element not as a regular expression but as a list of all valid characters.
When specifying search constraints for the NumAsAlphabet element, you can use drag-and-drop to copy the settings from the Relations section of the NumAsRegularExpression element into the same section of the current element. Alternatively, the following code can be written in the Advanced pre-search relations field:
SearchElements.InvoiceNumber is specified as its Source element. At this stage, the creation of a FlexiLayout to detect “Invoice number” fields is complete.
If, for some reason, the method described earlier is not sufficient for detecting the data field (whether its format is known or unknown), one more element (of type Object Collection) can be created in the group. In this project, it is an Object Collection element named NumAsObjectCollection.It is not actually needed given the good quality of the images in this project and is only shown as an example (the Disable command is specified for it).An additional Object Collection element might be needed when it is difficult to predict pre-recognition results on different pages, but the search area can be accurately described, preventing unwanted information from getting into the hypotheses.
Why the regular expression improves reliability
The following question may arise: why is a regular expression needed if the field can sometimes be detected without it? The answer is that the use of a regular expression makes the search more reliable. If this element is found, then you can be sure that you have found the very line that you need. This information can then be safely used to detect further elements and their relations. When the search constraints are lax, you cannot be absolutely sure that you have found exactly what you need. This may happen if the image is very noisy. In such cases, the use of a Character String element with a specified alphabet can lead to an excessive percentage of errors (the Percentage of non-alphabet characters parameter). As a result, the element will either not be detected at all or be detected only partially. The following figure shows an example of such a situation.




