[英]Regex: Match a specific character then a number
I am trying to match a specific character with a number followed by a full stop, ie V1.
我正在尝试将一个特定字符与一个数字匹配,后跟一个句号,即
V1.
or V2.
或
V2.
I decided to start with just trying to match the character and number but it doesnt seem to be working, after numerous Google searches I believe this to be correct but obviously it isnt. 我决定从尝试匹配字符和数字开始,但是它似乎不起作用,经过无数次Google搜索后,我认为这是正确的,但显然不是。 TIA
TIA
var regex = new Regex("\b[V][0-9]\b")
var replaced = regex.Replace(path, string.Empty);
The below regex would match V
plus the ollowing one or more numbers only if it's followed by a dot. 下面的正则表达式仅在其后跟一个点时才与
V
加上一个或多个数字匹配。
new Regex(@"\bV\d+\.")
Explanation: 说明:
\\b
Word boundary which matches between a word character and a non-word character. \\b
单词字符和非单词字符之间匹配的单词边界。 V
Matches a literal V
V
匹配文字V
\\d+
Matches one or more digits. \\d+
匹配一个或多个数字。 Use only \\d
if the following number is a single digit number. \\d
。 \\.
Matches a literal dot.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.