How do I find a value with in a substring REGEX

Apr 02, 2017 at 02:17 PM


avatar image


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.


10 |10000 characters needed characters left characters exceeded

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.

* Please Login or Register to Answer, Follow or Comment.

2 Answers

Horst Keller
Apr 02, 2017 at 02:21 PM

Read the documentation and play with DEMO_REGEX.


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

Show 2 Share
10 |10000 characters needed characters left characters exceeded


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"



Petros Yannoutsos
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
Sandra Rossi Apr 03, 2017 at 08:08 AM

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).

10 |10000 characters needed characters left characters exceeded
Skip to Content