字符之间的正则表达式 - 最后匹配

时间:2013-05-26 12:20:22

标签: .net regex

我正在搜索匹配上一个\_

之间的值的正则表达式

示例:

输入\\\ezbe.local\folder1\folder2\folder3\33248a-48596-a54qsd-4d7d98_2

输出33248a-48596-a54qsd-4d7d98

1 个答案:

答案 0 :(得分:5)

那将是

[^\\]*(?=_[^\\]*$)

<强>解释

[^\\]*   # Match any number of non-backslash characters
(?=      # if the following is true after the matched text:
 _       # There is a _
 [^\\]*  # followed only by non-backslash characters
 $       # until the end of the string.
)        # End of lookahead assertion