我想在PowerShell 7.2.4中删除某个字符串的某些部分,该怎么办?

发布于 2025-02-06 04:12:33 字数 302 浏览 3 评论 0原文

我有字符串“ url”:“ https://maven.fabricmc.net/net/fabricmc/fabricmc/fabric-installer/0.11.0/fabric-installer-0.11.11.0.jar”。我想从字符串中删除所有内容,但https://maven.fabricmc.net/net/fabricmc/fabricmc/fabric-installer/0.11.11.0/fabric-installer-0.11.11.0.jar(我想要也要删除报价)。

我该怎么做?

I have the string "url": "https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.11.0/fabric-installer-0.11.0.jar". I want to remove everything from the string except https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.11.0/fabric-installer-0.11.0.jar (I want to remove the quotes as well).

How do I go about it?

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

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

发布评论

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

评论(3

风月客 2025-02-13 04:12:33
$str = """url"": ""https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.11.0/fabric-installer-0.11.0.jar"""
$str.Split(""": """)[1].Replace("""","")
$str = """url"": ""https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.11.0/fabric-installer-0.11.0.jar"""
$str.Split(""": """)[1].Replace("""","")
辞慾 2025-02-13 04:12:33

我想到的最短
可能具有不正确的索引,只需测试切换“ 3”

( $str -split """ )[3]

The shortest I could think of
Might have the incorrect indexnumber, just test switching '3'

( $str -split """ )[3]
故笙诉离歌 2025-02-13 04:12:33

您可以使用-replace操作员并提取所需的部分。

'"url": "https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.11.0/fabric-installer-0.11.0.jar"' -replace '"url": "(.+)"','$1'

但是,由于这似乎是JSON格式,您可能会在整个内容上使用Convertfrom-Json,然后通过DOT表示法访问属性。

这要比尝试将JSON的匹配部分或字符串匹配部分容易得多。

$converted = Get-Content file.json | ConvertFrom-Json
$converted.url

You could use the -replace operator and extract the section you want.

'"url": "https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.11.0/fabric-installer-0.11.0.jar"' -replace '"url": "(.+)"','$1'

However since this appears to be in JSON format you may be better off using ConvertFrom-Json on the entire thing and then accessing the property through dot notation.

It's slightly easier than trying to regex or string match sections of JSON.

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