Regex 如何使用正则表达式检查字符串中的序列
我想检查输入字符串的格式是否正确^[\d-.]+$表达式只检查数字和。(点)和-(减)的存在性,但我还想检查其序列 假设我想用计算器。而且-仅此而已。如何得到满足以下所有条件的正则表达式Regex 如何使用正则表达式检查字符串中的序列,regex,c#-4.0,Regex,C# 4.0,我想检查输入字符串的格式是否正确^[\d-.]+$表达式只检查数字和。(点)和-(减)的存在性,但我还想检查其序列 假设我想用计算器。而且-仅此而已。如何得到满足以下所有条件的正则表达式 Regex.IsMatch(input, @"^[\d-\.]+$") //this expression works for below conditions only if string v1="10-20-30"; // should return true if string v
Regex.IsMatch(input, @"^[\d-\.]+$")
//this expression works for below conditions only
if string v1="10-20-30"; // should return true
if string v1="10-20"; // should return true
if string v1="10.20"; // should return true
if string v1="10R20"; // should return false
if string v1="10@20"; // should return false
if string v1="10-20.30.40-50"; // should return true
if string v1="10"; // should return true
//above expression not works for below conditions
if string v1="10--20.30"; // should return false
if string v1="10-20-30.."; // should return false
if string v1="--10-20.30"; // should return false
if string v1="-10-20.30"; // should return false
if string v1="10-20.30."; // should return false
大概是
var pattern = @"^(\d+(-|\.))*\d+$";
我应该为你做这项工作
这个正则表达式的“意思”是:
问候像魅力一样有效。很好的解释,谢谢