正则表达式匹配和字符串通配符c# [英] Regex Match and string wildcards c#
本文介绍了正则表达式匹配和字符串通配符c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了这行代码并想知道是否有人可以解释字符串通配符@_?< test> \w +)+。usf在这行代码中是什么意思?
I came across this line of code and wondering if anyone can explain what the string wildcard @"_?<test>\w+)+.usf" means in this line of code?
string Participant
Match filematch = Regex.Match(file.Name, Participant + @"_(?<test>\w+)+.usf");
谢谢!
Thanks!
推荐答案
@只是意味着从字面上取字符串所以你不需要逃避特殊字符。
_是字面下划线字符。
?意味着前一个模式可能不存在或一次
\ w是任何字母数字或下划线字符
+表示它可以存在1次或多次
)是一个紧密的括号。由于没有开括号,这将是错误的。 char应该被转义为'\)'
。将匹配除新行之外的任何字符
usf意味着字符串应该有一个usf
除了正则表达式被破坏之外,正则表达式匹配:
_abcd_efg_h#usf
它会在其他文本中找到此匹配:
sgfsjgfsjfg# _abcd_efg_h#usf ksdfksdjfhksdfh
i认为你可能想要修复'。'使其成为'\。',它与文字'。'字符匹配,但我想这里有很多其他问题。
希望有所帮助^ _ ^
Andy
@ just means to take the string literally so you don't need to escape special chars.
_ is a literal underscore char.
? means that the previous pattern may exist none or one times
\w is any alphanumeric or underscore char
+ means it can exist 1 or many times
) is a close parenthesis. As there is no open parenthesis, this will error. The char should be escaped to be literal like '\)'
. will match any char except new line
usf means that the string should have a usf
other than the fact that the regex is broken, the regex would match:
_abcd_efg_h#usf
it will find this match in other text:
sgfsjgfsjfg#_abcd_efg_h#usfksdfksdjfhksdfh
i think that you may want to fix the '.' to make it a '\.' which would match the literal '.' char, but I imagine there are lots of other issues here.
Hope that helps ^_^
Andy
这篇关于正则表达式匹配和字符串通配符c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文