正则表达式包含大小写数字(常用数字的正则表达式)

public static class StringHelper{,我来为大家科普一下关于正则表达式包含大小写数字?以下内容希望对你有帮助!

正则表达式包含大小写数字(常用数字的正则表达式)

正则表达式包含大小写数字

public static class StringHelper

{

//分数、带分数

public static string sMatchNumInch = @"(([1-9]\d*-)?[1-9]\d*/[1-9]\d*|[1-9]\d*)""";

//数字

public static string sMatchNum = @"((-|)([1-9] \d*|0)(\.\d )?|0)";

//整数

public static string sMatchNumInt = @"((|-)[1-9] (\d )?|0)";

//正整数

public static string sMatchNumIntPositive = @"([1-9] (\d )?)";

//负整数

public static string sMatchNumIntNegative = @"(-[1-9] (\d )?)";

//非负整数

public static string sMatchNumIntNonNegative = @"([1-9] (\d )?|0)";

//非正整数

public static string sMatchNumIntNonPositive = @"(-[1-9] (\d )?|0)";

//正数

public static string sMatchNumPositive = @"(([1-9] \d*)?((|0)\.\d )?)";

//负数

public static string sMatchNumNegative = @"(-([1-9] \d*|0)(\.\d )?)";

//非负数

public static string sMatchNumNonNegative = @"(([1-9] \d*)?((|0)\.\d )?)";

//非正数

public static string sMatchNumNonPositive = @"(-([1-9] \d*|0)(\.\d )?|0)";

/// <summary>

/// 判断字符串是否是数字

/// </summary>

/// <param name="str"></param>

/// <param name="nt"></param>

/// <returns></returns>

/// <summary>

public static bool IsNumType(this string str, NumType nt)

{

if (str == "")

return false;

string matchString = "";

switch (nt)

{

case NumType.Number:

//数字

matchString = sMatchNum;

break;

case NumType.PositiveInt:

//正整数

matchString = sMatchNumIntPositive;

break;

case NumType.NonNegativeInt:

//非负整数(正整数 0)

matchString = sMatchNumIntNonNegative;

break;

case NumType.NonPositiveInt:

//非正整数(负整数 0)

matchString = sMatchNumIntNonPositive;

break;

case NumType.NegativeInt:

//负整数

matchString = sMatchNumIntNegative;

break;

case NumType.Int:

//整数

matchString = sMatchNumInt;

break;

case NumType.NonNegative:

//非负数(正数 0)

matchString = sMatchNumNonNegative;

break;

case NumType.Positive:

//正数

matchString = sMatchNumPositive;

break;

case NumType.NonPositive:

//非正数(负数 0)

matchString = sMatchNumNonPositive;

break;

case NumType.Negative:

//负数

matchString = sMatchNumNegative;

break;

default:

break;

}

return Regex.IsMatch(str, matchString, RegexOptions.IgnoreCase);

}

/// <summary>

/// 第1位:9表示"非",1表示"数",2表示"整数"

/// 末位:1表示正,0表示负

/// </summary>

public enum NumType

{

/// <summary>

/// 浮点数

/// </summary>

Number = 1,

/// <summary>

/// 整数

/// </summary>

Int = 2,

/// <summary>

/// 正数

/// </summary>

Positive = 11,

/// <summary>

/// 负数

/// </summary>

Negative = 10,

/// <summary>

/// 正整数

/// </summary>

PositiveInt = 21,

/// <summary>

/// 负整数

/// </summary>

NegativeInt = 20,

/// <summary>

/// 非正数

/// </summary>

NonPositive = 911,

/// <summary>

/// 非负数

/// </summary>

NonNegative = 910,

/// <summary>

/// 非正整数

/// </summary>

NonPositiveInt = 921,

/// <summary>

/// 非负整数

/// </summary>

NonNegativeInt = 920,

}

}

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页