SAP REGEX ABEXA

Get Example source ABAP code based on a different SAP table
  


ARTICLE

Regular Expressions
The example demonstrates how to search for regular expressions.
An extended example that also allows replacements is DEMO_REGEX_TOY.

ABAP_SOURCE_CODE
ABAP_EXEC

ABAP_DESCRIPTION
The example displays a screen in which a text line and a regular expression can be entered. The program scans the text line text for the first or all areas that match the search pattern defined in the regular expression regx and highlights these areas in a result field; you may select case distinction. For the search the statement REPLACE is used which embeds the found location between ' tgl to the left and ' tgr to the right. The operator $0 is used as a placeholder for the found location in the replacement text repl. In method display the text is formatted for the presentation of the found locations in HTML format and displayed.
The predefined example text is: 'Cathy's cat with the hat sat on Matt's mat.'
and the predefined regular expression is: (.AT)|(<(><<)>.at>)
The regular expression describes
a sequence of three characters, where the first is any single character and the other two are 'AT', or
a word made of three characters, where the first is any single character and the other two are 'at'.
Depending on the search settings, the following locations will be found:
The search for the first occurrence without case distinction finds the 'Cat' of 'Cathy'. This location matches the expression .AT, but not the expression <(><<)>.at>.
The search for the first occurrence with case distinction finds the word 'cat'. This location matches the expression <(><<)>.at> , but not the expression .AT.
The search for all occurrences without case distinction finds all three subsequences consisting of three characters that end with 'at': 'Cat', 'cat', 'hat', 'sat', 'Mat', and 'mat'. All locations match the expression .AT. However, only the words 'cat', 'hat', 'sat' and 'mat' match the expression <(><<)>.at>.
The search for all occurrences with case distinction finds the words 'cat', 'hat', 'sat' and 'mat'. They all match the expression <(><<)>.at>. But none of the locations matches .AT.