04-02-2017 3:17 PM
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
04-02-2017 3:21 PM
Read the documentation and play with DEMO_REGEX.
| is a special character that must be escaped by \.
04-02-2017 3:21 PM
Read the documentation and play with DEMO_REGEX.
| is a special character that must be escaped by \.
10-12-2017 3:52 AM
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
04-12-2018 7:55 AM
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
04-03-2017 7:04 AM
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.
04-03-2017 9: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).