Delete all text before a string
-
Hello, I am trying to delete all text in a file before the first instance of a string. There are multiple instances of the string, but I need to essentially find the first occurrence of the string, and delete all text preceding the string.
As an example, the file is:
aaa
bbb
ccc
111
222
333
2021-05-26abcdefg
ddd
444
123456789
2021-05-26I need the locate the FIRST occurrence of the string - “2021-05-26” and delete all text before that string, NOT including “abcdefg” on the same line. So I would need to delete the lines, aaa | bbb | ccc | 111 | 222 | 333
The desired output being:
2021-05-26abcdefg
ddd
444
123456789
2021-05-26I have been looking for a regex command for this, but haven’t had any luck so far. Any assistance is appreciated.
Notepad++ v8.1.9.2 (32-bit)
Build time : Nov 21 2021 - 04:27:12
Path : C:\Program Files (x86)\Notepad++\notepad++.exe
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Enterprise (64-bit)
OS Version : 2009
OS Build : 19042.1415
Current ANSI codepage : 1252
Plugins : mimeTools.dll NppConverter.dll NppExport.dll -
FIND =
(?s)\A.*?(2021-05-26)
(?s)
will allow.
to match newline (or you can set the flag in the dialog box)\A
represents the start of the file.*?
says “0 or more, as few as possible”(...)
puts whatever’s in the parens in a group2021-05-26
literal string you want to match
REPLACE =
$1
$1
refers to the contents of the first group from the FIND
SEARCH MODE = regular expression
Do the replacement
----
Useful References