当前位置:网站首页>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
}
边栏推荐
- 航運船公司人工智能AI產品成熟化標准化規模應用,全球港航人工智能/集裝箱人工智能領軍者CIMC中集飛瞳,打造國際航運智能化標杆
- 一大波开源小抄来袭
- A wave of open source notebooks is coming
- What is Base64?
- 山东老博会,2022中国智慧养老展会,智能化养老、适老科技展
- leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
- The difference between full-time graduate students and part-time graduate students!
- Steps to create P8 certificate and warehousing account
- The rebound problem of using Scrollview in cocos Creator
- [quick start of Digital IC Verification] 20. Basic grammar of SystemVerilog learning 7 (coverage driven... Including practical exercises)
猜你喜欢
[quick start of Digital IC Verification] 24. AHB sramc of SystemVerilog project practice (4) (AHB continues to deepen)
HPDC smart base Talent Development Summit essay
Shipping companies' AI products are mature, standardized and applied on a large scale. CIMC, the global leader in port and shipping AI / container AI, has built a benchmark for international shipping
Three. JS introductory learning notes 07: external model import -c4d to JSON file for web pages -fbx import
LeetCode3_ Longest substring without duplicate characters
[quick start of Digital IC Verification] 19. Basic grammar of SystemVerilog learning 6 (thread internal communication... Including practical exercises)
Syntax of generator function (state machine)
[quick start of Digital IC Verification] 18. Basic grammar of SystemVerilog learning 5 (concurrent threads... Including practical exercises)
[quick start of Digital IC Verification] 20. Basic grammar of SystemVerilog learning 7 (coverage driven... Including practical exercises)
When opening the system window under UE4 shipping, the problem of crash is attached with the plug-in download address
随机推荐
Cocos uses custom material to display problems
Clang compile link ffmpeg FAQ
有钱人买房就是不一样
Shipping companies' AI products are mature, standardized and applied on a large scale. CIMC, the global leader in port and shipping AI / container AI, has built a benchmark for international shipping
The download button and debug button in keil are grayed out
[quick start of Digital IC Verification] 25. AHB sramc of SystemVerilog project practice (5) (AHB key review, key points refining)
Getting started with webgl (3)
【花雕体验】15 尝试搭建Beetle ESP32 C3之Arduino开发环境
C4D learning notes 2- animation - timeline and time function
Starting from 1.5, build a microservice framework link tracking traceid
[wechat applet] Chapter (5): basic API interface of wechat applet
Create lib Library in keil and use lib Library
Mysql database backup script
After UE4 is packaged, mesh has no material problem
[quickstart to Digital IC Validation] 20. Basic syntax for system verilog Learning 7 (Coverage Driven... Including practical exercises)
Align individual elements to the right under flex layout
Three. JS introductory learning notes 07: external model import -c4d to JSON file for web pages -fbx import
Syntax of generator function (state machine)
Numpy --- basic learning notes
[quick start of Digital IC Verification] 18. Basic grammar of SystemVerilog learning 5 (concurrent threads... Including practical exercises)