SAP REGEX POSIX PCRE IMPROVE
Get Example source ABAP code based on a different SAP table
ABAP_REGEX - New Features in PCRE Compared to POSIX
While topic
An introduction to some of these features is provided in the following, the list is however far from complete.
ITOC
Making Use of New Features for Patterns
Lazy Quantifiers
The most obvious downside of POSIX regular expressions in ABAP is the lack of lazy (also known as non-greedy or reluctant) quantifiers.
In PCRE a quantifier can be made lazy by adding a trailing
0 or 1, preferred 0
0 or more, as few as possible
1 or more, as few as possible
at least n, no more than m, as few as possible
at least n, as few as possible
ABAP_EXAMPLE_VX5
Difference between greedy and non-greedy behavior,
ABEXA 01498
ABAP_EXAMPLE_END
Look-behind Assertions
positive look-behind assertion; succeeds if the current match position is preceded by the given pattern
negative look-behind assertion; succeeds if the current match position is not preceded by the given pattern
ABAP_EXAMPLE_VX5
Leading and trailing look-behind assertions, like look-ahead assertions, are not part of the actual match.
ABEXA 01499
ABAP_EXAMPLE_END
Multiline Mode
In some scenarios it is necessary to respect line feeds during matching, e.g. matching something only if it is located at the beginning of a line. PCRE makes this very convenient by providing a large amount of control over the handling of multiple lines in the matching process.
When creating a regular expression using method
Despite their names, single line and multi line mode are not mutually exclusive and can be combined.
It is also possible to set these options directly in the pattern, which is especially useful for regular expressions used in statements
ABAP_EXAMPLE_VX5
While the first regular expression matches only the beginning of the character string, the second one also matches the beginning of new lines that are defined by the syntax
ABEXA 01500
ABAP_EXAMPLE_END
Named Capture Groups
PCRE supports the naming of capture groups, meaning you can assign a name to a capture group, e.g. using the
ABAP_EXAMPLE_VX5
The regular expression matches the character string. The capture group is used by its name to match further occurrences of the pattern defined for the group.
ABEXA 01501
ABAP_EXAMPLE_END
Subroutine Calls and Recursion
Apart from referring to the content of a group via backreferences, PCRE supports calling groups as subroutines using the
ABAP_EXAMPLE_VX5
The example shows the calling of groups as subroutines in three blocks:
ABEXA 01502
ABAP_EXAMPLE_END
Callouts
Callouts are another powerful feature. It invokes ABAP code from within the pattern during the matching process, passing data from the pattern to the callout routine.
Callouts are achieved with the
ABAP_EXAMPLE_ABEXA
ABAP_EXAMPLE_END
Making Use of New Features for Replacements
Conditional Substitution
PCRE's conditional substitution syntax allows you to check if a certain capture group did participate in the match, specifying different replacement strings for when it did and did not participate.
ABAP_EXAMPLE_VX5
Conditional substitutions with
ABEXA 01503
ABAP_EXAMPLE_END
Case Conversion
Using the
The case conversion syntax can also be combined with conditional substitution.
ABAP_EXAMPLE_VX5
Replacements with case conversions. The latter two use conditional substitutions.
ABEXA 01504
ABAP_EXAMPLE_END