Search code examples
regexreplaceregex-lookaroundsregex-groupregex-greedy

RegEx for matching everything except words starting with a plus sign


Sample string: +Z XA( 0,1,6,22,26,33,34,35,36,25,24) +DD +I +M >x1 >bdz +A

Result should be: +Z +DD +I +M +A or Z DD I M A

The regex (\+\w+) seems to find all tokens, but I don't know how to define the replace pattern. I'd like to remove everything else.

I use Omnis7 but the regex engine is a compiled Delphi library that I used to extend Omnis7. The regex engine is a full implementation of regex. I tried to find the regex with an online regex tool (regex101.com).

How do I solve this problem?


Solution

  • Use:

    • Find: (\+\w+\h?)|.
    • Replace: $1

    Demo