Reputation: 69
I have three lines of tab-separated values:
The first two have 'SELL' or 'BUY' as first value but the third one has not, hence a Tab mark where I wrote ______
:
I would like to capture the following using Regex:
My expression ^(BUY|SELL).+?\r\n\t
does not work as it gets me this:
I do know why outputs this - adding an lazy-maker '?' obviously won't help. I don't get lookarounds to work either, if they are the right means at all. I need something like 'Match \r\n\t only or \r\n(?:^\t) at the end of each line'.
The final goal is to make the three lines look at this at the end, so I will need to replace the match with capturing groups:
Can anyone point me to the right direction?
Upvotes: 1
Views: 92
Reputation: 15482
You can use the following regex ((BUY|SELL)[^\n]+\n)\s+
and replace with \1\2
.
Regex Match Explanation:
((BUY|SELL)[^\n]+\n)
: Group 1
(BUY|SELL)
: Group 2
BUY
: sequence of characters "BUY" followed by a space|
: orSELL
: sequence of characters "SELL" followed by a space[^\n]+
: any character other than newline\n
: newline character\s+
: any space charactersRegex Replace Explanation:
\1
: Reference to Group 1\2
: Reference to Group 2Check the demo here. Tested on Notepad++
in a private environment too.
Note: Make sure to check the "Regular expression" checkbox.
Regex
Upvotes: 1
Reputation: 91415
^(BUY|SELL).+\R\K\t
$1\t
. matches newline
Explanation:
^ # beginning of line
(BUY|SELL) # group 1, BUY or SELL
.+ # 1 or more any character but newline
\R # any kind of linebreak
\K # forget all we have seen until this position
\t # a tabulation
Replacement:
$1 # content of group 1
\t # a tabulation
Screenshot (before):
Screenshot (after):
Upvotes: 1