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)\Arepresents the start of the file.*?says “0 or more, as few as possible”(...)puts whatever’s in the parens in a group2021-05-26literal string you want to match
REPLACE =
$1$1refers to the contents of the first group from the FIND
SEARCH MODE = regular expression
Do the replacement
-—
Useful References
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login