Search code examples
regexnotepad++regex-lookaroundsregex-group

Regex handling "|" in Text


I got the following text:

Code = ABCD123 | Points = 30
Code = ABCD333 | Points = 44

At the end, I want to removing anything except the Code, output:

ABCD123
ABCD333

I actually tried it with Code = | P.+

But I don't know how to get "|" removed. Currently, I have just ÀBCD333 | left as an example. I'm struggling there.


Solution

  • Assuming the code only consists of word characters, you may use the following:

    ^Code = (\w+).+$
    

    ..and replace with:

    \1
    

    Demo.

    If the code can be anything, you may use something like this instead:

    ^Code = (.+?)[ ]\|.+$