近日在做某项目时候,里面涉及到了与数学表达式有关的计算,为了高效的适配数学表达式现以正则表达式进行提取予以分享,若有需要的小伙伴可参考,具体如下:
/// <summary> /// 正则表达式助手 /// </summary> public class RegularHelper { /// <summary> /// 管段Code规则 /// 示例:WS2-WS3 /// </summary> public const string RegularPipleCode = @"^((([0-9a-zA-Z])+){1}?\-(([0-9a-zA-Z])+){1}?){1}?$"; /// <summary> /// 支持不带负号的小数或者整数 /// 示例:0.25,2.5,2,15 /// </summary> public const string RegularDecimalV1 = @"^((\d+(\.\d+)?))+$"; /// <summary> /// 支持待负号的小数或者整数 /// 示例:-2.5,2.5,0,2,15 /// </summary> public const string RegularDecimalV2 = @"^(((\-)?\d+(\.\d+)?)|(\d+(\.\d+)?))+$"; /// <summary> /// 缺陷密度数学表达式 /// 匹配2.5),2.5],-2.5),-2.5] /// </summary> public const string RegularDesityV1 = @"^(((\-)?\d+(\.\d+)?)|(\d+(\.\d+)?))+(\)|\]){1}$"; /// <summary> /// 缺陷密度数学表达式 /// 匹配(2.5,[2.5,(-2.5,(-2.5 /// </summary> public const string RegularDesityV2 = @"^(\(|\[){1}(((\-)?\d+(\.\d+)?)|(\d+(\.\d+)?))+$"; /// <summary> /// 缺陷密度数学表达式 /// 匹配(2.5,5.6],(2.5,5.6),[2.5,5.6],[2.5,5.6) /// </summary> public const string RegularDesityV3 = @"^(\(|\[){1}(((\-)?\d+(\.\d+)?)|(\d+(\.\d+)?))+(\,){1}(((\-)?\d+(\.\d+)?)|(\d+(\.\d+)?))+(\)|\]){1}$"; /// <summary> /// 数学表达式 /// 匹配RI<5,RI≤5,RI≤-5, /// </summary> public const string RegularPlIndexV1 = @"^[a-zA-Z]+(\<|\≤|\=|\>|\≥){1}(((\-)?\d+(\.\d+)?)|(\d+(\.\d+)?))+$"; /// <summary> /// 数学表达式 /// 匹配2<RI≤5,2<RI<5,-5<RI<5 /// </summary> public const string RegularPlIndexV2 = @"^(((\-)?\d+(\.\d+)?)|(\d+(\.\d+)?))+(\<|\≤|){1}[a-zA-Z]+(\<|\≤|){1}(((\-)?\d+(\.\d+)?)|(\d+(\.\d+)?))+$"; /// <summary> /// 数数学表达式-非数字开头, /// 匹配RI<,RI≤,RI2≤,RI2>,RI2≥,开头为数字或字符,直到<、≤、=、>、≥结束 /// </summary> public const string RegularNoStartWithDedimal = @"^[a-zA-Z]+(((\-)?\d+(\.\d+)?)|(\d+(\.\d+)?))*[≤<=>≥]+"; /// <summary> /// 数数学表达式 /// 数字开头表达式 /// </summary> public const string RegularStartWithDecimal = @"^(((\-)?\d+(\.\d+)?)|(\d+(\.\d+)?))+"; /// <summary> /// 数数学表达式 /// 数字结尾表达式 /// </summary> public const string RegularEndWithDecimal = @"(((\-)?\d+(\.\d+)?)|(\d+(\.\d+)?))+$"; /// <summary> /// 数数学表达式 /// 包含数字表达式 /// </summary> public const string RegularContainDecimal = @"(((\-)?\d+(\.\d+)?)|(\d+(\.\d+)?))+"; }
标签:const,string,c#,适配,RI,正则表达式,2.5,public,表达式 From: https://www.cnblogs.com/oumi/p/17462016.html