delete text before | and then, using notepad
I am trying to use notepad++ and regular expressions to edit a document. I have text in this format
How would I do that to get this:
your problem intrigued me so I felt I had to solve it. From your example I assumed that the
|is a delimiter and that you can have anywhere from 4 fields upwards (example shows 4, 5 and 6 fields). I also assumed that you want the 2nd and 4th field every time with the delimiter between.
So my regex (regular expression) requires that the search mode under “Replace” function is set to “regular expression” and also have the wrap around ticked.
You should be able to copy the Find What field directly (grab the red text) and it’s probably best to do so.
It might look a bit daunting but what we have is:
^[^|]+ :start at beginning of line and consume characters so long as a
|is not encountered.
[|] :consume 1 character which should be the
|as the previous expression had to stop when the next character was a
The next 4 expressions repeat the prior ones. The round brackets around some allows up to keep the characters we capture in those portions of the expression.
([^|\r\n]+) consumes characters until either a
|or an end of line is encountered. This is needed as we don’t know whether the line is ONLY 4 fields or more.
(\R|\z) consumes an end of line or end of file.
We capture the groups we need and then recreate them (including the end of line/file) to replace the line.
See how it works on your data and come back if further issues which might require modification of the regex, or even to let us know if it worked.
You may have noticed some
\missing from my description, I did not until now. It is an unfortunate side effect of the window you type the post in. Its interpreted and sometimes this (or worse) happens. I hope you got the idea anyways.
thank you very much friend for helping me, very good clarification
Just a variant of your regex, which uses lazy quantifiers and non capturing groups :
@guy038 , thanks you