I have three lines of tab-separated values:
- SELL 2022-06-28 12:42:27 39.42 0.29 11.43180000 0.00003582
- BUY 2022-06-28 12:27:22 39.30 0.10 3.93000000 0.00001233
- _____2022-06-28 12:27:22 39.30 0.19 7.46700000 0.00002342
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 it does it - 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'... Can anyone point me to the right direction? I am using www.rexegg.com as a learner.
Btw, 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:
(I am using Notepad .)
CodePudding user response:
- Ctrl H
- Find what:
^(BUY|SELL). \R\K\t - Replace with:
$1\t - CHECK Match case
- CHECK Wrap around
- CHECK Regular expression
- UNCHECK
. matches newline - Replace all
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):
CodePudding user response:
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 2BUY: 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 characters
Regex Replace Explanation:
\1: Reference to Group 1\2: Reference to Group 2
Check the demo here. Tested on Notepad in a private environment too.
Note: Make sure to check the "Regular expression" checkbox.
Regex






