首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >禁用curl中的正则表达式解析

禁用curl中的正则表达式解析
EN

Stack Overflow用户
提问于 2021-11-05 11:15:06
回答 1查看 109关注 0票数 0

我试图使用接受正则表达式作为参数之一的API。

我发现curl在这里很聪明,并且解析正则表达式本身,而不是把它作为URL的一部分。因此,每当我启动curl命令时,它就会发出70000个HTTP请求。它应该只做一个。

示例:https://api.example.com/v1/?regex=(123[4-5][6-7][8-9])

在本例中,我希望文本HTTP请求是,嗯,那个。

相反,我得到了:

代码语言:javascript
运行
复制
[1/8]: https://api.example.com/v1/?regex=(123468) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123468)
curl: (6) Could not resolve host: api.example.com

[2/8]: https://api.example.com/v1/?regex=(123469) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123469)
curl: (6) Could not resolve host: api.example.com

[3/8]: https://api.example.com/v1/?regex=(123478) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123478)
curl: (6) Could not resolve host: api.example.com

[4/8]: https://api.example.com/v1/?regex=(123479) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123479)
curl: (6) Could not resolve host: api.example.com

[5/8]: https://api.example.com/v1/?regex=(123568) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123568)
curl: (6) Could not resolve host: api.example.com

[6/8]: https://api.example.com/v1/?regex=(123569) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123569)
curl: (6) Could not resolve host: api.example.com

[7/8]: https://api.example.com/v1/?regex=(123578) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123578)
curl: (6) Could not resolve host: api.example.com

[8/8]: https://api.example.com/v1/?regex=(123579) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123579)
curl: (6) Could not resolve host: api.example.com

如何禁用curl所具有的正则表达式解析?

我检查了curl --help all,没有关于这种解析的任何内容。我还检查了手册页的卷曲。这里也什么也没有,这似乎是一个完全没有文档的“有用”特性。

它看起来确实是curl,而不是shell,因为wget似乎没有发生这种情况,因为wget只产生一个(失败的请求)。

试图用\转义括号似乎会阻止解析,但也会以一种看起来不太正确的方式转换字符:

代码语言:javascript
运行
复制
root@voip:/tmp# wget "https://api.example.com/v1/?regex=(123\[4-5\]\[6-7\]\[8-9\])"
--2021-11-05 11:26:03--  https://api.example.com/v1/?regex=(123%5C[4-5%5C]%5C[6-7%5C]%5C[8-9%5C])
Resolving api.example.com (api.example.com)... failed: Name or service not known.
wget: unable to resolve host address ‘api.example.com’
root@voip:/tmp# wget "https://api.example.com/v1/?regex=(123\[4-5]\[6-7]\[8-9])"
--2021-11-05 11:26:25--  https://api.example.com/v1/?regex=(123%5C[4-5]%5C[6-7]%5C[8-9])
Resolving api.example.com (api.example.com)... failed: Name or service not known.
wget: unable to resolve host address ‘api.example.com’
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-05 16:03:58

若要使用{}和[]禁用URL序列和范围,可以使用选项-g

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69852393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档