gpt4 book ai didi

regex - MSBuild 社区需要 RegexReplace 从路径中删除尾部斜杠

转载 作者:行者123 更新时间:2023-12-04 05:41:01 25 4
gpt4 key购买 nike

我正在尝试使用 MSBuild 社区任务从 OutputPath 的末尾删除斜杠

这是我到目前为止。

<RegexReplace Input="$(OutputPath)" Expression="\$" Replacement="" Count="1">
<Output ItemName="FormattedOutputPath" TaskParameter="Output" />
</RegexReplace>
<Message Text="@(FormattedOutputPath)"/>

不幸的是,该消息只是返回我的路径,最后仍然带有斜杠。
路径是 C:\MyDirectory\

看来我的表达不正确

任何人都可以帮忙吗?

最佳答案

斜杠用作转义字符,因此在模式中,您必须通过另一个斜杠转义斜杠字符:

<RegexReplace Input="$(OutputPath)" Expression="\\$" Replacement="" Count="1">
<Output ItemName="FormattedOutputPath" TaskParameter="Output" />
</RegexReplace>
<Message Text="@(FormattedOutputPath)"/>

为了更好地理解转义,请参见以下示例:
  • $表示行/字符串的结尾
  • \$表示美元符号字符
  • \\表示斜线字符
  • \\$表示行/字符串末尾的斜杠字符
  • 关于regex - MSBuild 社区需要 RegexReplace 从路径中删除尾部斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11247522/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com