A regular expression class

Source: Internet
Author: User

Using System;
Namespace Regexlib {
////// Summary of Class1.
Public class Regexlib {
Public Regexlib (){
/// TODO: add the constructor logic here //
}
// Search for the input string and return all href = "..." Values
String DumpHrefs (String inputString ){
Regex r;
Match m;
R = new Regex ("hrefs * = s *(? :"(? <1> [^ "] *)" | (? <1> S + ))",
RegexOptions. IgnoreCase | RegexOptions. Compiled );
For (m = r. Match (inputString );
M. Success; m = m. NextMatch ()){
Return ("Found href" + m. Groups [1]);
}
}
// Verify the Email address
Bool IsValidEmail (string strIn ){
// Return true if strIn is in valid e-mail format.
Return Regex. isMatch (strIn, @ "^ ([w-.] +) @ ([0-9] {1, 3 }. [0-9] {1, 3 }. [0-9] {1, 3 }.) | ([w-] + .) +) ([a-zA-Z] {2, 4} | [0-9] {1, 3}) (]?) $ ");
}
// The Date Format of dd-mm-yy replaces the date format of mm/dd/yy.
String MDYToDMY (String input ){
Return Regex. Replace (input, "B (? D {1, 2 })/(? D {1, 2 })/(? D {2, 4}) B "," $ {day}-$ {month}-$ {year }");
}
// Verify whether it is decimal
Bool IsValidDecimal (string strIn ){
Return Regex. IsMatch (strIn, @ "[0]. d {1, 2} | [1]");
}
// Verify whether the phone number is used
Bool IsValidTel (string strIn ){
Return Regex. IsMatch (strIn, @ "(d + -)? (D {4 }-? D {7} | d {3 }-? D {8} | ^ d {7, 8}) (-d + )? ");
}
// Verification year, month, and day
Bool IsValidDate (string strIn ){
Return Regex. IsMatch (strIn, @ "^ 2d {3 }-(? : 0? [1-9] | 1 [0-2])-(? : 0? [1-9] | [1-2] d | 3 [0-1]) (? : 0? [1-9] | 1d | 2 [0-3]) :(? : 0? [1-9] | [1-5] d ):(? : 0? [1-9] | [1-5] d) $ ");
}
// Verify the suffix
Bool IsValidPostfix (string strIn ){
Return Regex. IsMatch (strIn ,@".(? I: gif | jpg) $ ");
}
// Verify whether the character ranges from 4 to 12
Bool IsValidByte (string strIn ){
Return Regex. IsMatch (strIn, @ "^ [a-z] {4, 12} $ ");
}
// Verify the IP address
Bool IsValidIp (string strIn ){
Return Regex. isMatch (strIn, @ "^ (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]) $ ");
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.