【发布时间】:2020-11-04 13:16:29
【问题描述】:
我的源代码中有一个带有href="example.com/page" 的htm 文件,我怎样才能获得“”之间的链接?
到目前为止,我已经尝试过修改这段代码:
@echo off
setlocal EnableDelayedExpansion
set "str="
set "string=stuff href="example.com/page"end morestuff"
set string=!string:href=^
!
set string=!string:end=^
!
FOR /F skip^=1eol^= %%S in ("!string!") do if NOT DEFINED str set "str=%%S"
echo(!str!
pause > nul
但是在第 6 行看来,将 href 更改为 href=" 会破坏代码,并将 end 更改为 " 也破坏了某些东西,想知道是否可以解决此问题或是否有替代方法?
【问题讨论】:
-
您不能在子字符串替换表达式的搜索字符串中使用等号,因为
=分隔搜索和替换字符串;我会首先使用href作为搜索字符串,当删除它时(通过set "string=!string:*=href=!"),我也会使用子字符串扩展来删除=,例如if "!string:~,1!"=="=" set "string=!string:~1!";那么您可以将"指定为for /F的分隔符...
标签: string batch-file cmd