当前位置:网站首页>Regular expression string
Regular expression string
2022-07-07 15:53:00 【Le_ Sam】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace tablegen2.common
{
#region Regular expression string
/// <summary>
/// Regular expression string
/// </summary>
public class StrRegex
{
#region Regular expressions replace strings
/// <summary>
/// Regular expressions replace strings
/// </summary>
/// <param name="inputString"> String content </param>
/// <param name="pattern"> Replace character </param>
/// <param name="replaceStr"> Replacement value </param>
/// <returns></returns>
public static string RegexReplace(string inputString, string pattern, string replaceStr)
{
try
{
return Regex.Replace(inputString, pattern, replaceStr);
}
catch (Exception e)
{
return e.Message;
}
}
#endregion
#region Determine whether the string is a positive integer
/// <summary>
/// Determine whether the string is a positive integer
/// </summary>
/// <param name="objString"> String to match </param>
/// <returns> Return true and false value ,true: matching ;false: Mismatch </returns>
public static bool IsInt(String objString)
{
Regex myReg = new Regex(@"^\d+$");
return myReg.IsMatch(objString);
}
#endregion
#region Judge whether the input string is all in English ( Case insensitive )
/// <summary>
/// Judge whether the input string is all in English ( Case insensitive )
/// </summary>
/// <param name="objString"> The string to match </param>
/// <returns> Return true and false value ,true: matching ;false: Mismatch </returns>
public static bool isEnglishString(String objString)
{
Regex myReg = new Regex(@"^[a-zA-Z]+$");
return myReg.IsMatch(objString);
}
#endregion
/// <summary>
/// Returns the number in a string
/// </summary>
/// <param name="objString"></param>
/// <returns></returns>
public static string RunNumber(string objString)
{
return Regex.Match(objString, "[0-9]+").Value.ToString();
}
/// <summary>
/// Returns the left character in the string
/// </summary>
/// <param name="objString"></param>
/// <returns></returns>
public static string RunLeftString(string objString)
{
return Regex.Match(objString, "[%*/+ -.A-Za-z]+").Value.ToString();
}
/// <summary>
/// Returns the right character in the string
/// </summary>
/// <param name="objString"></param>
/// <returns></returns>
public static string RunRightString(string objString)
{
return Regex.Match(objString, "[%*/+ -.A-Za-z]+$").Value.ToString();
}
/// <summary>
/// Returns the characters in a string
/// </summary>
/// <param name="objString"></param>
/// <returns></returns>
public static string RunString(string objString)
{
return Regex.Match(objString, "[A-Za-z]+").Value.ToString();
}
#region Judge whether the input string is Chinese
/// <summary>
/// Judge whether the input string is Chinese
/// </summary>
/// <param name="objString"> The string to match </param>
/// <returns> Return true and false value ,true: matching ;false: Mismatch </returns>
public static bool isChinese(String objString)
{
Regex myReg = new Regex(@"^[\u4e00-\u9fa5]+$");
return myReg.IsMatch(objString);
}
#endregion
#region Judge whether the input string is in English and numbers ( English is not case sensitive )
/// <summary>
/// Judge whether the input string is in English and numbers ( English is not case sensitive )
/// </summary>
/// <param name="objString"> The string to match </param>
/// <returns> Return true and false value ,true: matching ;false: Mismatch </returns>
public static bool isEngNum(String objString)
{
Regex myReg = new Regex(@"^[*/+-a-zA-Z0-9]+$");
return myReg.IsMatch(objString);
}
#endregion
#region Judge whether the input string is in English A-D And numbers ( English is limited to A-D English is not case sensitive )
/// <summary>
/// Judge whether the input string is in English A-D And numbers ( English is limited to A-D English is not case sensitive )
/// </summary>
/// <param name="objString"> The string to match </param>
/// <returns> Return true and false value ,true: matching ;false: Mismatch </returns>
public static bool isEngNumMax(String objString)
{
Regex myReg = new Regex(@"^[a-dA-D0-9]+$");
return myReg.IsMatch(objString);
}
#endregion
#region Judge whether it is a combination of English and numbers
/// <summary>
/// Judge whether it is a combination of English and numbers
/// </summary>
/// <param name="objString"></param>
/// <returns></returns>
public static bool InEngNum(string objString)
{
//Regex myReg = new Regex(@"^(?![0-9]+$)[a-zA-Z0-9]{1,25}$");
//return myReg.IsMatch(objString);"^[a-zA-Z]\w{5,17}$"
return Regex.IsMatch(objString, @"^[*/+-a-zA-Z0-9]{1,20}$");
}
#endregion
#region Judge whether the input string is in English , Numbers , chinese ( English is not case sensitive )
/// <summary>
/// Judge whether the input string is in English , Numbers , chinese ( English is not case sensitive )
/// </summary>
/// <param name="objString"> The string to match </param>
/// <returns> Return true and false value ,true: matching ;false: Mismatch </returns>
public static bool isChineseEngNum(String objString)
{
Regex myReg = new Regex(@"^[\u4e00-\u9fa5a-zA-Z0-9]+$");
return myReg.IsMatch(objString);
}
#endregion
#region Judge whether the input string is decimal
/// <summary>
/// Judge whether the input string is decimal
/// </summary>
/// <param name="objString"> The string to match </param>
/// <returns> Return true and false value ,true: matching ;false: Mismatch </returns>
public static bool isFloat(String objString)
{
Regex myReg = new Regex(@"^[0-9]+[.][0-9]+|[0-9]+$");
return myReg.IsMatch(objString);
}
#endregion
#region Judge whether the date format is valid
/// <summary>
/// Judge whether the date format is valid
/// </summary>
/// <param name="objString"></param>
/// <returns></returns>
public static bool IsDate(String objString)
{
Regex myReg = new Regex(@"\b(?<year>\d{2,4})-(?<month>\d{1,2})-(?<day>\d{1,2})\b");
return myReg.IsMatch(objString);
}
#endregion
#region Judge whether the string conforms to this regular expression
/// <summary>
/// Judge whether the string conforms to this regular expression
/// </summary>
/// <param name="str"> The string to match </param>
/// <param name="regString"> Regular string ( Such as :^[1-9]{1}$)</param>
/// <returns> Return true and false value ,true: matching ;false: Mismatch </returns>
public static bool IsFitStrings(String str, String regString)
{
Regex objPattern = new Regex(regString);
bool returnValue = objPattern.IsMatch(str);
return returnValue;
}
#endregion
#region Judge whether the string is a mobile number or a small smart number
/// <summary>
/// Judge whether the string is a mobile number or a small smart number
/// </summary>
/// <param name="telNumber"> The string to match </param>
/// <returns> Return true and false value ,true: matching ;false: Mismatch </returns>
public static bool IsMobile(string telNumber)
{
if (telNumber == "")
return false;
Regex myReg = new Regex(@"^((\d{11,12})|(\d{7}))$");
return myReg.IsMatch(telNumber);
}
#endregion
#region Determine if the string is Email Address
/// <summary>
/// Determine if the string is Email Address
/// </summary>
/// <param name="email"> The string to match </param>
/// <returns> Return true and false value ,true: matching ;false: Mismatch </returns>
public static bool IsEmail(string email)
{
if (email == "")
{
return false;
}
Regex myReg = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
return myReg.IsMatch(email);
}
#endregion
#region Judge whether the string is a landline ( Such as xxx-xxxxxxx-xxx)
/// <summary>
/// Judge whether the string is a landline ( Such as xxx-xxxxxxx-xxx)
/// </summary>
/// <param name="tel"> The string to match </param>
/// <returns> Return true and false value ,true: matching ;false: Mismatch </returns>
public static bool IsTel(string tel)
{
if (tel == "")
return false;
Regex myReg = new Regex(@"^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}(-\d{1,5})?$");
return myReg.IsMatch(tel);
}
#endregion
#region Determine whether it is a postal code
/// <summary>
/// Determine whether it is a postal code
/// </summary>
/// <param name="Zip"></param>
/// <returns></returns>
public static bool IsValidZip(string Zip)
{
return Regex.IsMatch(Zip, @"^[a-z0-9 ]{3,12}$");
}
#endregion
#region Determine whether it is a valid ID number
/// <summary>
/// Determine whether it is a valid ID number
/// </summary>
/// <param name="IdCard"></param>
/// <returns></returns>
public static bool IsIdCard(string IdCard)
{
return Regex.IsMatch(IdCard, @"^\d{15}|\d{18}$");
}
#endregion
#region Returns the split string
/// <summary>
/// Returns the split string
/// </summary>
/// <param name="Str"> The set of strings to split </param>
/// <param name="spliststr"> Specify split character </param>
/// <returns></returns>
public static string FindStr(string Str, string spliststr)
{
string[] str2 = System.Text.RegularExpressions.Regex.Split(Str, @"[" + spliststr + "]+");
foreach (string i in str2)
{
return i.ToString();
}
return "";
}
#endregion
}
#endregion
}
边栏推荐
- webgl_ Enter the three-dimensional world (1)
- [quick start of Digital IC Verification] 24. AHB sramc of SystemVerilog project practice (4) (AHB continues to deepen)
- Three. JS introductory learning notes 05: external model import -c4d into JSON file for web pages
- numpy--疫情数据分析案例
- 【数字IC验证快速入门】19、SystemVerilog学习之基本语法6(线程内部通信...内含实践练习)
- [markdown grammar advanced] make your blog more exciting (IV: set font style and color comparison table)
- Please supervise the 2022 plan
- Shader basic UV operations, translation, rotation, scaling
- Matlab experience summary
- Align individual elements to the right under flex layout
猜你喜欢

webgl_ Graphic transformation (rotation, translation, zoom)

Cocos creator collision and collision callback do not take effect

The bank needs to build the middle office capability of the intelligent customer service module to drive the upgrade of the whole scene intelligent customer service

Yunxiaoduo software internal test distribution test platform description document

C4D learning notes 1- animation - animation key frames

Vertex shader to slice shader procedure, varying variable

The difference between full-time graduate students and part-time graduate students!

Gd32 F3 pin mapping problem SW interface cannot be burned

Apache Doris刚“毕业”:为什么应关注这种SQL数据仓库?

2022第四届中国(济南)国际智慧养老产业展览会,山东老博会
随机推荐
航天宏图信息中标乌鲁木齐某单位数据库系统研发项目
[original] all management without assessment is nonsense!
The download button and debug button in keil are grayed out
TS typescript type declaration special declaration field number is handled when the key key
尤雨溪,来了!
2022第四届中国(济南)国际智慧养老产业展览会,山东老博会
HPDC smart base Talent Development Summit essay
Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
Migration and reprint
Async and await
Getting started with webgl (1)
Ue4/ue5 multi thread development attachment plug-in download address
Cocos creator collision and collision callback do not take effect
[quick start of Digital IC Verification] 24. AHB sramc of SystemVerilog project practice (4) (AHB continues to deepen)
Learn good-looking custom scroll bars in 1 minute
Three. JS introductory learning notes 07: external model import -c4d to JSON file for web pages -fbx import
Apache Doris刚“毕业”:为什么应关注这种SQL数据仓库?
Use of SVN
Numpy --- basic learning notes
webgl_ Enter the three-dimensional world (1)