Splitting Text with Regular Expressions

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Data Sources and Targets > MapForce FlexText > FlexText and Regular Expressions >

Splitting Text with Regular Expressions

When you need to split text into two or more fragments, you can optionally use a regular expression as separator. This is an alternative, more advanced option as compared to separating text by means of single or multiple consecutive characters.

 

The option to split text by means of regular expressions becomes available in FlexText when the following conditions are true:

 

The container is of type Split Once or Repeated Split.
The Mode option is set to delimited (floating), delimited (line based), or delimited (line starts with).

FlexTextRegEx01

Sample FlexText template which uses regular expressions to separate text

The options applicable to regular expressions are as follows.

 

Regular expression

To use a regular expression as text separator, switch this option to yes. To use simple text as separator, switch this option to no (this is the default value).

Separator pattern

If the Regular expression option is switched to yes, a Separator Pattern text box becomes available where you can enter the regular expression that must act as separator. In the FlexText template illustrated above, the regular expression [A-Z]{1}[0-9]{5} matches exactly one alphanumeric character, followed by exactly five numeric characters (for example, "P00011"). All such occurrences are highlighted in the preview and act as text splitting separator.

Separator for writing

The Separator for writing option is meaningful when the following conditions are true:

 

The FlexText component is a target component
Mode is set to delimited (floating).

 

Enter in this field the string to be written to the target component at the occurrence where a regular expression match was found.


© 2019 Altova GmbH