Need help in replace and delete all similar sentence
-
Need help on how to replace and delete all this particular sentence only in my notepad.
i have near to 100+ ‘‘VRDP4-XXXXXXXXXXX’’
SM1+VRDP4-OOCU4868933:20240906151200:;;::KOJ’
SM1+VRDP4 OOCU7704147:20240905132700:;;::KOJ’
SM1+VRDP4-CBHU4477056:20240906141100:;;::KOJ’ -
@TOMMY-TAN
Anybody that can help you, will need more details of what you are asking. I suggest the links below to start.
https://community.notepad-plus-plus.org/topic/15739/faq-request-for-help-without-sufficient-information-to-help-you
https://community.notepad-plus-plus.org/topic/21925/faq-formatting-forum-posts
https://community.notepad-plus-plus.org/topic/15765/faq-where-to-find-regular-expressions-regex-documentation -
@TOMMY-TAN, I’ll take a guess at what you want.
Using Notepad++'s Regular Expression mode then do a search/replace using:
Search:
(?-i)(?<=^SM1\+)VRDP4-[A-Z]{4}[0-9]{7}(?=:202[0-9][01][0-9][0-3][0-9][012][0-9][0-5][0-9]00:;;::KOJ’$)
Replace: (leave this blank or empty)The search thing has four main parts:
(?-i)
Tells Notepad++ to turn the “ignore case” flag off so that things such asVRDP
in the pattern only match an upper caseVRDP
in the data.(?<=^SM1\+)
matches the stuff before the VRDP4-… thing you want to delete or replace.VRDP4-[A-Z]{4}[0-9]{7}
matches the VRDP4-… thing. I made the assumption that it has four letters followed by seven digits. You should be able to figure out how to make the adjustments should VRDP4-… thing not always be four letters followed by seven digits. I noticed that your second line of the example data was missing the hyphen or dash betweenVRDP4
and the rest of the thing. If your data sometimes has a space and other times has a hyphen or dash then useVRDP4[ -]...
instead ofVRDP4-
(?=:20[0-9][0-9][01][0-9][0-3][0-9][012][0-9][0-5][0-9]00:;;::KOJ’$)
is overkill but it matches the stuff after the VRDP4- thing. I saw that the first part looked like a date/time formatted as YYYYMMDDHH with zeros for the seconds and so set up the pattern to match the years 2000 to 2099. If the seconds are not always zero then you can use[0-5][0-9]
instead of00
.
You can test this from the Mark tab the Search/replace dialog box. Just do a Mark-All and the stuff that gets highlighted will be the matches and will be the data that gets deleted should you do a replace-all on the search/replace tab.
-
Hello @tommy-tan, @lycan-thrope, @mark-olson and All,
Given the INPUT text, below
SM1+VRDP4-OOCU4868933:20240906151200:;;::KOJ’ SM1+VRDP4 OOCU7704147:20240905132700:;;::KOJ’ SM1+VRDP4-CBHU4477056:20240906141100:;;::KOJ’ DEF456SM1+VRDP4-CBHU4477056:20240906141100:;;::KOJ’ AB9+VRDP4-CBHU4477056:20240906141100:;;::KOJ’
A more simple formulation would be to use one of the three regexes, below :
-
(?-is)VRDP4.+?(?=:)
which matches any string beginning by an uppercase stringVRDP4
till the very first colon of the current line -
(?-is)(?<=^SM1\+)VRDP4.+?(?=:)
if, in addition, the uppercase stringVRDP4
is preceded by an uppercase stringSM1+
, strictely beginning a line -
(?-is)(?<=SM1\+)VRDP4.+?(?=:)
if, in addition, the uppercase stringVRDP4
is just preceded by an uppercase stringSM1+
Now , if we consider the general example below :
ABC XYZ 123ABC XYZ ABCXYZ 123ABCXYZ
As said above :
-
The regex
(?-i)(?<=^ABC)XYZ
would find any uppercase stringXYZ
if predeced by an uppercase stringABC
strictely beginning a line -
The regex
(?-i)(?<=ABC)XYZ
would find any uppercase stringXYZ
, if preceded by an uppercase stringABC
However the two regexes
(?-i)^(?<=ABC)XYZ
or(?-i)(?<=ABC)^XYZ
cannot find any match ! Why ? Just because the^
is a regex assertion which is a shorthand of the(?<=\n|\r)
syntax. Thus, these two syntaxes can be replaced by(?-i)(?<=\n|\r)(?<=ABC)XYZ
and(?-i)(?<=ABC)(?<=\n|\r)XYZ
. And it obvious that the string XYZ CANNOT be preceded, at the same time, with both an EOL character and the string ABC !For people who want to know the right syntaxes, in this specific case, they are
(?s-i)^(?<=ABC..)XYZ
and(?s-i)(?<=ABC..)^XYZ
, where the two dots represent an EOL char ! So, they both match an uppercase stringXYZ
, right after an uppercase stringABC\r\n
Note that the third syntax
(?s-i)(?<=ABC..)XYZ
, without any^
symbol, matches also the two uppercase stringsXYZ
, beginning a line
Actually, to be exhaustive, the later regex
(?s-i)(?<=ABC..)XYZ
matches any uppercase stringXYZ
, preceded by a fixed string of5
characters :-
The first three are the uppercase string
ABC
-
The following two chars can be absolutely any char ( standard or EOL characters )
Best Regards,
guy038
-