我需要从文本中提取一条线,并带有Ngrok链接的批次

发布于 2025-02-03 04:01:44 字数 1551 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮邮递员 2025-02-10 04:01:44
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "line={"tunnels":[{"name":"command_line","ID":"7769cea7b2843d7ded705c62afde8dd3","uri":"/api/tunnels/command_line","public_url":"https://32a6-203-89-122-249.ap.ngrok.io","proto":"https","config":{"addr":"http://localhost:4040","inspect":true},"metrics":{"conns":{"count":0,"gauge":0,"rate1":0,"rate5":0,"rate15":0,"p50":0,"p90":0,"p95":0,"p99":0},"http":{"count":0,"rate1":0,"rate5":0,"rate15":0,"p50":0,"p90":0,"p95":0,"p99":0}}}],"uri":"/api/tunnels"}"
SET "line=%line:[=%"
SET "line=%line:{=%"
SET "line=%line:]=%"
SET "line=%line:}=%"
SET "line=%line:":"=","%"
SET "line=%line:":=",%"
SET "public_url=undefined"
SET "assign_next="
FOR %%e IN (%line%) DO (
 ECHO %%e
 IF DEFINED assign_next SET "!assign_next!=%%~e"
 IF DEFINED %%~e (SET "assign_next=%%~e") ELSE (SET "assign_next=")
)
ECHO ------------------------
SET public_url
GOTO :EOF

不知道您将其用作示例的数据行被存储在哪里,因此我假设它在环境变量line中。

至于链接 - 您可以指定您的意思是哪个字段,或者也许是指指定为数据项public_url的链接。

因此 - 假设您的数据在line中,请使用字符串replace删除{[等。 /em>,然后每个“:” “”,“” 并遵循弹跳球...

设置<<代码>未定义的(只是一个有意义的字符串,没有魔术)和过程line,用简单的作为循环的简单作为可能引用的令牌的顺序。

Echo %% E命令仅用于显示以允许评估令牌。

nistion_next在循环之前 nothing

匹配定义的变量,然后接下来的令牌包含所需的数据,因此将nistion_next设置为 name 可以分配下一步标记的变量。

如果定义了nistion_next,则将当前令牌分配给nistion_next中包含的variablename。

...并使用SET显示结果。

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "line={"tunnels":[{"name":"command_line","ID":"7769cea7b2843d7ded705c62afde8dd3","uri":"/api/tunnels/command_line","public_url":"https://32a6-203-89-122-249.ap.ngrok.io","proto":"https","config":{"addr":"http://localhost:4040","inspect":true},"metrics":{"conns":{"count":0,"gauge":0,"rate1":0,"rate5":0,"rate15":0,"p50":0,"p90":0,"p95":0,"p99":0},"http":{"count":0,"rate1":0,"rate5":0,"rate15":0,"p50":0,"p90":0,"p95":0,"p99":0}}}],"uri":"/api/tunnels"}"
SET "line=%line:[=%"
SET "line=%line:{=%"
SET "line=%line:]=%"
SET "line=%line:}=%"
SET "line=%line:":"=","%"
SET "line=%line:":=",%"
SET "public_url=undefined"
SET "assign_next="
FOR %%e IN (%line%) DO (
 ECHO %%e
 IF DEFINED assign_next SET "!assign_next!=%%~e"
 IF DEFINED %%~e (SET "assign_next=%%~e") ELSE (SET "assign_next=")
)
ECHO ------------------------
SET public_url
GOTO :EOF

No idea where the data line you've used as an example is stored, so I've assumed it's in an environment variable line.

As for what you mean by the link - you could have specified which field you mean, or perhaps you mean the link specified as the data item public_url.

So - assuming your data is in line, use string-replace to delete {, [, etc. by replacing by nothing, then each ":" by "," and follow the bouncing ball...

Set the name(s) of the field(s) required to undefined (just a meaningful string, nothing magic) and process line with a simple for loop as a sequence of possibly-quoted tokens separated by commas.

The echo %%e command is simply for show to allow the token being evaluated to be seen.

assign_next is "set" to nothing before the for loop, so it will start as not defined

If a token matches a defined variable, then the next token contains the desired data, so set assign_next to the name of the variable to which to assign the next token.

If assign_next is defined, then assign the current token to the variablename contained in assign_next.

... and display results using set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文