With release version OP 2020 (ABAP 755) we get to use some new cool syntax features -> Regular Expressions (or seen more often as RegEx). There are a lot of materials on internet about RegEx and how to use RegEx with ABAP. I won't start another general topic about it, so please be free and check the web pages I added at the end of the document.
However, what really got me excited and thus, the today's subject, is RegEX with PCRE (Perl Compatible Regular Expressions) in ABAP SQL and CDS Views.

RegEx is a much more powerful tool than the classic ABAP patterns. Combining it with the "Top-Down Approach" of SAP HANA, we end up with some cool tricks that save both a lot of time (performance wise) and energy (coding wise).

Example

Let's formulate the following business case: there are some mistakes in the database. The letters in House Number fields should always be saved with uppercase letters. We need to check what entries have a House Number containing small letters and update them.

So, how can we select only the entries with lowercase letters?

SELECT * FROM adrc
    WHERE like_regexpr( pcre = '[a-z]', value = house_num1 ) = '1'  
    INTO TABLE @DATA(lt_address).
    
cl_demo_output=>display( lt_address ).

The statement above selects all the address lines in which the House Number contains a small letter character. '[a-z]' represents a range of all the letters from the alphabet in lowercase.

This approach is much cleaner than selecting all the lines and process them afterwards. I know this can be achieved without using RegEx. A select-options with 'CP' would do the trick, but boy if that wouldn't be a pain in the a** to build (believe me, I had to do it. The customer's system was a bit too old).

Materials

As promissed, if you want to learn more about it, I recommend the following topics:
Modern Regular Expressions in ABAP
Regular Expressions (RegEx) in Modern ABAP