您如何检查字符串是否在特定位置包含 int?
How do you check if a string contains an int at a specific location?
我想在继续之前确保文件夹的名称格式正确。下面的代码演示了我正在尝试做的事情,尽管 {char.IsDigit} 不起作用。我想用 "any digit" 的意思替换 char.IsDigit。
if(versionName == $"Release {char.IsDigit}.{char.IsDigit}.{char.IsDigit}.{char.IsDigit}")
{
//Do something
}
谢谢
您想将 Regex.IsMatch
与正则表达式一起使用,例如:
if(Regex.IsMatch(versionName, @"^Release \d\.\d\.\d\.\d$"))
{
//Do something
}
注意\d
只匹配单个数字,如果可以超过1个数字
@"^Release \d+\.\d+\.\d+\.\d+$"
并收紧一切:
@"^Release \d+(?:\.\d+){3}$"
见regex demo and its graph:
我想在继续之前确保文件夹的名称格式正确。下面的代码演示了我正在尝试做的事情,尽管 {char.IsDigit} 不起作用。我想用 "any digit" 的意思替换 char.IsDigit。
if(versionName == $"Release {char.IsDigit}.{char.IsDigit}.{char.IsDigit}.{char.IsDigit}")
{
//Do something
}
谢谢
您想将 Regex.IsMatch
与正则表达式一起使用,例如:
if(Regex.IsMatch(versionName, @"^Release \d\.\d\.\d\.\d$"))
{
//Do something
}
注意\d
只匹配单个数字,如果可以超过1个数字
@"^Release \d+\.\d+\.\d+\.\d+$"
并收紧一切:
@"^Release \d+(?:\.\d+){3}$"
见regex demo and its graph: