Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Replace substring within Brackets with regex

casualCoder
Explorer
0 Kudos
679

Hi,

the following String is given: '{12ZT-}716Ghdnsba'.

I want to cut the text within the Brackets, so the result would be '716Ghdnsba'.

Can anybody show me the approach with Regular Expressions? (regex?)

4 REPLIES 4

raymond_giuseppi
Active Contributor
0 Kudos
526

You can replace a regex pattern in a string using a syntax such as

REPLACE PCRE <regex pattern> IN <string> WITH ``.

For example try with a pattern such as \{.*\} (try demo report DEMO_REGEX)

Sandra_Rossi
Active Contributor
0 Kudos
526

PCRE or POSIX?

or just use substring_after( ... sub = '}' ), no?

thkolz
Contributor
0 Kudos
526
DATA: v_string TYPE string VALUE '{12ZT-}716Ghdnsba'.

REPLACE PCRE '\{.*\}' IN v_string WITH ''.

touzik_itc
Active Participant
0 Kudos
526

Or something like this

match( val = '{12ZT-}716Ghdnsba' regex = '[^}]*$' )