I would like to delete the text from D-E-F
to G-H-I
from the text "before processing" below.
A-B-C;hogehogehoge
D-E-F;fugafuga
piyopiyopiyo
G-H-I; hogerahogera
A-B-C;HOGEHOGEHOGE
D-E-F;FUGAFUGAFUGA
PIYOPIYOPIYO
G-H-I;HOGERAHOGERA
・
・
・
A-B-C;hogehogehoge
G-H-I; hogerahogera
A-B-C;HOGEHOGEHOGE
G-H-I;HOGERAHOGERA
・
・
・
Referring to Yahoo! Chiebukuro post, I grouped A-B-C
and G-H-I
and wrote "Not Found" as follows:
Search string: (A-B-C)[^(G-H-I)]*(G-H-I)
Replacement string:\r\nG-H-I
It works if the search is for a single character, but isn't it enough to simply group strings?
In this case, please let me know how it is appropriate to describe it.
My software is the Merry text editor.
regular-expression editor
For your information, I have never used the "Merry Text Editor", but here is an example of Python description (pre-processed text: temp.txt
).
Use *?
instead of *
(for example, +?
??
).Also, you must use [\s\S]
(all characters except blank or blank) instead of .
because the part you want to delete.
import re
with open('temp.txt', 'r') as f:
before=f.read()
after=re.sub(r'(A-B-C.*\n)[\s\S]*?(G-H-I)', r'\1\2', before)
print(after, end=')
A-B-C;hogehogehoge
G-H-I; hogerahogera
A-B-C;HOGEHOGEHOGE
G-H-I;HOGERAHOGERA
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
578 Understanding How to Configure Google API Key
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.