Regular Expression Examples
Regular Expressions are patterns that can be matched against text strings. Regular Expressions may include literal characters that match the text string directly, and operators that match against one or more characters (for example, a dot (.) matches against any character).
Regular Expressions are used by:
- Analyze ABAP Quality actions to find ABAP source code that matches quality rules.
- Filter by Patterns actions to filter the contents of a Table parameter or dataset.
- Find Objects in SAP actions to retrieve matching objects from the specified SAP system.
- Match Strings actions to find strings that match the specified patterns.
Sample Object Names
The Regular Expressions below may be matched against the following sample object names:
123PROG
123PROG1
999TCOD02
USR
USR01
USR02
USR03
/ICORP/ZVA01
ZVA1
ZVA01
Matching Literal Characters
Regular Expressions that do not contain any special characters match against the literal text occurring anywhere in the text string. For example, the pattern ZVA01 matches against ZVA01 and /ICORP/ZVA01. These matches are case-sensitive.
Matching a Single Character
The dot (.) operator matches against a single character or number. For example, the pattern USR. matches against USR01, USR02 and USR03 (in each case, the dot matches 0).
Matching Characters at the Beginning of a String
The ^ operator anchors a match to the beginning of a string. For example, the pattern ^ZVA01 matches against ZVA01, but not /ICORP/ZVA01.
Matching Characters at the End of a String
The $ operator anchors a match to the end of a string. For example, the pattern 01$ matches against USR01, /ICORP/ZVA01 and ZVA01.
Matching Characters at Word Boundaries
The \b operator matches one or more characters at the start of a line or at the beginning of a word.
Matching a Single Character
The \w operator matches against a single character (A-Z). For example, the pattern US\w$ matches against USR only in the above list.
Matching a Single Digit
The \d operator matches against a single digit (0-9). For example, the pattern ^USR0\d matches against USR01, USR02 and USR03.
Matching Spaces
The \s operator matches against a single space (however there are no spaces in the above examples).
Escaping Characters
The \ operator is used for ‘escaping’ characters. For example, the pattern \\ matches against \.
Repeating Matches One or More Times
The + operator matches the preceding character one or more times. For example, the pattern \d+\w+\d+ matches against 123PROG1, 123PROG1 and 999TCOD02.
Repeating Matches Zero or More Times
The * operator matches the preceding character zero or more times. For example, the pattern 123PROG\d* matches against 123PROG and 123PROG1.
Optional Characters
The ? operator marks the preceding character as optional. For example, the pattern ^ZVA0?1 matches against ZVA01 and ZVA1.
Alternative Matches
The | operator allows you to specify alternative matches, for example the pattern USR0(1|3) matches USR01 and USR03.