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: 

How do I find a value with in a substring REGEX

0 Kudos

HI,

I am trying to find a character with in a substring. For example I have a | delimited file and want to remove all | values between " ".

|2017-03-29|"DEC | User X"|Y|2017-03-29|"DEC | User Z"|Y|

I am trying to located the | in the substring |"DEC | User X"| and any other occurrence it appears.

Thanks

1 ACCEPTED SOLUTION

horst_keller
Product and Topic Expert
Product and Topic Expert

Read the documentation and play with DEMO_REGEX.

https://help.sap.com/http.svc/rc/abapdocu_751_index_htm/7.51/en-US/index.htm?file=abenregex_syntax_s...

| is a special character that must be escaped by \.

5 REPLIES 5

horst_keller
Product and Topic Expert
Product and Topic Expert

Read the documentation and play with DEMO_REGEX.

https://help.sap.com/http.svc/rc/abapdocu_751_index_htm/7.51/en-US/index.htm?file=abenregex_syntax_s...

| is a special character that must be escaped by \.

0 Kudos

Hi,

Thanks for the help.. I ended up doing the following

"[^"\\]*(?:\\.[^"\\]*)*"

|2017-03-29|"DEC | User X"|Y|2017-03-29|"DEC | User Z"|Y|

which gives me

"DEC | User X" & "DEC | User Z"

Regards

Petros

In fact, it seems that you don't want to locate the | characters,
but only parse what's inside 2 double quotes, with the \ character being
an escape character.

... REGEX 
  '"'           " Double quote
& '[^"\\]*'     " 0 character or list of any characters up to " or \
& '(?:'         " start of non-capturing group
&   '\\.'         " \ followed by any character
&   '[^"\\]*'     " list of any characters up to " or \
&   ')'           " end of group
& '*'           " Optional group or repeat the group 1 or more times

matt
Active Contributor

Probably it is better to ask this question on a dedicated Regex forum. Regex is a powerful, but sometimes quite difficult to use. I wouldn't expect ABAP developers to be expert with it.

Sandra_Rossi
Active Contributor

I'm surprised by the question: don't you want to keep the | inside "..." fields and remove the real | separators?

If I'm right, I think you should first split at fields in a first regular expression: ([|]|"[^"]+"|[^|]+), which would produce 3 types of elements, the separators (|), the "..." fields, and the other fields. Then delete the separators, and then loop at all "..." fields to remove quotes (and so, also keep the optional | if it's there).