Skip to content

Prefer Simpler String Functions over Plain Regex ​

WarningClean ABAP & Modern Syntax#EC PREF_PLAIN_REGEXRemote Enabled

Overview ​

Prefer Simpler String Functions to Regex.

ATC Finding Message: Regex pattern contains no metacharacters - use the simple sub / case parameter instead

Rationale ​

A regex literal that contains no metacharacters (such as . [ { ( ) * + ? ^ $ | or the escape backslash) performs a plain literal search yet pays the regex engine's parsing and backtracking cost. Replace plain literal patterns with the simple, cheaper and more readable sub / case parameters of find, count, replace or contains. Only literal patterns without metacharacters are flagged; textual FIND/REPLACE with REGEX is covered by no-obs-strings.

Non-Compliant ​

abap
result = replace( val = text
  regex = 'HELLO'
  with = 'WORLD' ).

Compliant ​

abap
result = replace( val = text
  sub = 'HELLO'
  with = 'WORLD' ).

Suppression ​

To suppress findings for this rule, append the pseudo-comment to the statement:

abap
" Standard pseudo-comment:
... "#EC PREF_PLAIN_REGEX

" SAP CI_ prefix format:
... "#EC CI_PREF_PLAIN_REGEX

Technical Details ​

Released under the MIT License.