我有这样的字符串。 AB24从字符串中分离字符和数字,vb.net
我需要分别获得AB和24分开。使用正则表达式会很好。
我已经使用,
Regex.Match("AB24", "\d+$").Value
得到24个。
现在我需要让AB出来吗?请帮我..
我有这样的字符串。 AB24从字符串中分离字符和数字,vb.net
我需要分别获得AB和24分开。使用正则表达式会很好。
我已经使用,
Regex.Match("AB24", "\d+$").Value
得到24个。
现在我需要让AB出来吗?请帮我..
您可以使用正则表达式来单独编号
Regex.Replace("AB24", "(?:[0-9]+\.?[0-9]*|\.[0-9]+)", "")
您可以使用正则表达式来单独文本
Regex.Replace("AB24", "[^\A-Z]", "")
,你可以简单地使用lastNo = Regex.Match(txtNextLot.Text, "/^[A-z]+$/").Value
我试过了。但是这只返回一个空字符串。 – samithagun
使用捕获组()
来分隔你的比赛。
Dim m As Match = Regex.Match("AB24", "^([A-Z]+)([0-9]+)$")
If (m.Success) Then
Console.WriteLine(m.Groups(1).Value)
Console.WriteLine(m.Groups(2).Value)
End If
输出
AB
24
感谢您的回复。 – samithagun
感谢。我使用Regex.Replace(“AB24”,“\ d + $”,“”),它的工作完美。 – samithagun