在txt文件中,我想在“ live /”和“ / number”之间替换字符串
just a random text/live/y8mJepPsAk/UgZtTKd6A8/79953
just a random text/live/SvSvuq6JV5/eE3dg0bAMr/79954
just a random text/live/eME6hoeNV9/PJa5HwhUnF/88974
just a random text/live/bUue7Vprac/sue0ZmGzwy/78385
just a random text/live/UznB0niAEp/MgspVk69tX/93994
我尝试了以下代码:
Replace : live/.*?/[0-9]
Replace with : live/my-new-text/
但是问题是删除了“ /”之后的第一个数字。
答案 0 :(得分:0)
(?<=live/).+?(?=/\d+$)
my-new-text
. matches newline
取决于Npp版本,您可以改用:
live/\K.+?(?=/\d+$)
说明:
(?<=live/) : positive lookbehind, make sure we have "live/" before
.+? : 1 or more any character but newline, not greedy
(?=/\d+$) : positive lookahead, make sure we have slash and 1 or more digits
给定示例的结果
just a random text/live/my-new-text/79953
just a random text/live/my-new-text/79954
just a random text/live/my-new-text/88974
just a random text/live/my-new-text/78385
just a random text/live/my-new-text/93994
答案 1 :(得分:0)
只需对原始正则表达式进行较小修正:
ECHO A > myfile.txt
C:\Windows\System32\FIND.EXE "A" myfile.txt
使用正向前行代替数字。这样就不会被替换。
另一种替代方法是匹配数字,然后使用\ 1恢复该数字:
C:\Windows\System32\FINDSTR.EXE /C:"A" myfile.txt