-1

How do I find a value with in a substring REGEX

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

Add comment
10|10000 characters needed 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.

  • Get RSS Feed

2 Answers

  • Apr 02, 2017 at 02:21 PM

    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_specials.htm

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

    Add comment
    10|10000 characters needed characters exceeded

    • Sandra Rossi 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
      
  • 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).

    Add comment
    10|10000 characters needed characters exceeded

Skip to Content