【问题标题】:MSBuild Community Taks RegexReplace remove trailing slash from pathMSBuild 社区任务正则表达式替换从路径中删除尾部斜杠
【发布时间】:2012-06-30 03:26:10
【问题描述】:

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

这是我目前所拥有的。

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

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

看来我的表达不正确

谁能帮忙?

【问题讨论】:

    标签: regex msbuild msbuildcommunitytasks


    【解决方案1】:

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

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

    为了更好地理解转义,请参阅以下示例:

    1. $ 代表行/字符串结束
    2. \$ 表示美元符号字符
    3. \\ 代表斜线字符
    4. \\$ 表示行/字符串末尾的斜线字符

    【讨论】:

    • 谢谢 - 我已经在 javascript 正则表达式测试器上测试了表达式并且它有效,但是当我看着它时,我猜测可能是这种情况。再次感谢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多