Java Common Tool class regexputils, regular Expression tool class

Source: Internet
Author: User

 PackageCom.test.core.util;ImportOrg.apache.log4j.Logger;Importorg.apache.oro.text.regex.MalformedPatternException;ImportOrg.apache.oro.text.regex.Pattern;ImportOrg.apache.oro.text.regex.PatternCompiler;ImportOrg.apache.oro.text.regex.PatternMatcher;ImportOrg.apache.oro.text.regex.Perl5Compiler;ImportOrg.apache.oro.text.regex.Perl5Matcher; Public Final classRegexputils {Private StaticLogger log = Logger.getlogger (regexputils.class); Privateregexputils () {}/*** Match Image * * Format:/relative path/filename. suffix (suffix gif,dmp,png) * * Match:/FORUM/HEAD_ICON/ADMINI2005111_FF. GIF or ADMINI2005111.DMP * * * does not match: C:/admins4512.gif **/     Public Static FinalString icon_regexp = "^ (/{0,1}//w) {1,}//. (gif|dmp|png|jpg) $|^//w{1,}//. (gif|dmp|png|jpg) $ "; /*** Match Email address * * Format: [email protected] * * match: [email protected] or [email protected] * * does not match: [email protected] or [email protected] **/     Public Static FinalString email_regexp = "(?:/ /w[-._//w]*//[email protected]//w[-._//w]*//w//.//w{2,3}$) "; /*** Match match and extract URL * * * format: xxxx://xxx.xxx.xxx. XX/XXX.XXX?XXX=XXX * * Match:http://www.suncer.comor News://www * * does not match: C:/window **/     Public Static FinalString url_regexp = "(//w+)://([^/:]+) (://d*)? ([^#//s]*) "; /*** Match and extract HTTP * * Format:Http://XXX.XXX.XXX.XX/XXX.XXX?XXX=XXXor Ftp://XXX.XXX.XXX or *Https://XXX* * Match:http://www.suncer.com: 8080/index.html?login=true * * does not match: News://www **/     Public Static FinalString http_regexp = "(HTTP|HTTPS|FTP)://([^/:]+) (://d*)? ([^#//s]*) "; /*** Match Date * * * Format (first not 0): XXXX-XX-XX or Xxxx-x-x * * * Range: 1900--2099 * * * Match: 2005-04-04 * * * * mismatch: 01-01-01 **/     Public Static FinalString date_bars_regexp = "^ ((((19) {1}| ( {1}) \\d{2}) |\\d{2})-[0,1]?\\d{1}-[0-3]?\\d{1}$ "; /*** Match Date * * Format: XXXX/XX/XX * * * Range: * * * match: 2005/04/04 * * * does not match: 01/01/01 **/     Public Static FinalString date_slash_regexp = "^[0-9]{4}/(((0[13578]| ( 10|12))/(0[1-9]|[ 1-2][0-9]|3[0-1]) | (02-(0[1-9]|[ 1-2][0-9]) | ((0[469]|11)/(0[1-9]|[ 1-2][0-9]|30))) $ "; /*** Match Phone * * Format: 0xxx-xxxxxx (10-13 digits first must be 0) or 0XXX XXXXXXX (10-13 digits first must be 0) or * * (0XXX) XXXXXX XX (11-14 first must be 0) or XXXXXXXX (6-8 digits first not 0) or * XXXXXXXXXXX (11 digits first not 0) * * * match: 0371-123456 or (0371) 1234567      or (0371) 12345678 or 010-123456 or * 010-12345678 or 12345678912 * * * does not match: 1111-134355 or 0123456789 * */     Public Static FinalString phone_regexp = "^ (?: 0 [0-9] {2,3} [-//S] {1}|//(0[0-9]{2,4}//)) [0-9]{6,8}$|^[1-9]{1}[0-9]{5,7}$|^[1-9]{1}[0-9]{10}$ "; /*** Match ID * * Format: xxxxxxxxxx (10-bit) or xxxxxxxxxxxxx (13-bit) or xxxxxxxxxxxxxxx (15-bit) or * XXXXXXXXXXXXXXXXXX ( 18 bit) * * Match: 0123456789123 * * mismatch: 0123456 **/     Public Static FinalString id_card_regexp = "^//d{10}|//d{13}|//d{15}|//d{18}$"; /*** Match ZIP code * * Format: XXXXXX (6 bit) * Match: 012345 * * mismatch: 0123456 **/     Public Static FinalString zip_regexp = "^[0-9]{6}$";//Match zip code    /*** does not include special character matching (the string does not include the symbol math square number ^ single quotation mark ' double quotation mark ' semicolon; comma, cap number: math minus-Right angle bracket > Left angle Bracket < backslash/* i.e. space, tab, carriage return, etc.) * * Format: x or one of the characters on the * * Match: 012345 * * mismatch: 0123456//;,:-<>//s].+$ "; //*/     Public Static FinalString non_special_char_regexp = "^[^ '/"; //Match zip code    /*** matches non-negative integers (positive integers + 0)*/     Public Static FinalString non_negative_integers_regexp = "^//d+$"; /*** Match does not include 0 non-negative integers (positive integers > 0)*/     Public Static FinalString non_zero_negative_integers_regexp = "^[1-9]+//d*$"; /*** * Match positive integer **/     Public Static FinalString positive_integer_regexp = "^[0-9]*[1-9][0-9]*$"; /*** * Match non-positive integer (negative integer + 0) **/     Public Static FinalString non_positive_integers_regexp = "^ ((-//d+) | ( 0+)) $ "; /*** * Match negative integer **/     Public Static FinalString negative_integers_regexp = "^-[0-9]*[1-9][0-9]*$"; /*** * Match integer **/     Public Static FinalString integer_regexp = "^-?//d+$"; /*** * match non-negative floating point number (positive floating point + 0) **/     Public Static FinalString non_negative_rational_numbers_regexp = "^//d+ (//.//d+)? $"; /*** * Match the positive floating point number **/     Public Static FinalString positive_rational_numbers_regexp = "^ ([0-9]+//.[ 0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*//. [0-9]+) | ([0-9]*[1-9][0-9]*)) $"; /*** * match non-positive floating-point number (negative floating-point number + 0) **/     Public Static FinalString non_positive_rational_numbers_regexp = "^ ((-//d+ (//.//d+)?) | (0+ (//.0+)?)) $"; /*** * Match negative floating point number **/     Public Static FinalString negative_rational_numbers_regexp = "^ (-([0-9]+//.[ 0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*//. [0-9]+) | ([0-9]*[1-9][0-9]*))) $"; /*** * Match floating point number **/     Public Static FinalString rational_numbers_regexp = "^ (-?//d+) (//.//d+)? $"; /*** * matches a string consisting of 26 English letters **/     Public Static FinalString letter_regexp = "^[a-za-z]+$"; /*** * matches a string consisting of 26 uppercase letters of the English alphabet **/     Public Static FinalString upward_letter_regexp = "^[a-z]+$"; /*** * matches a string consisting of 26 letters in lowercase **/     Public Static FinalString lower_letter_regexp = "^[a-z]+$"; /*** * matches a string consisting of a number and 26 English letters **/     Public Static FinalString letter_number_regexp = "^[a-za-z0-9]+$"; /*** * matches a string consisting of a number, 26 letters or underscores **/     Public Static FinalString letter_number_underline_regexp = "^//w+$"; /*** Case-sensitive formal expression batching * *@paramSource * Batch-sourced string *@paramRegExp * Regular Expressions for batch matching *@returnReturns False if the source string matches the requirement to return True*/     Public Static Booleanishardregexpvalidate (string source, string regexp) {Try {            //used to define the formal Expression object template typePatterncompiler compiler =NewPerl5compiler (); //Regular Expressions Compare batch objectsPatternmatcher Matcher =NewPerl5matcher (); //instance-size-case-sensitive formal expression templatesPattern Hardpattern =Compiler.compile (regexp); //returns the result of a batch            returnmatcher.contains (source, Hardpattern); } Catch(malformedpatternexception e) {Log.warn (e); }        return false; }}

Java Common Tool class regexputils, regular Expression tool class

Related Article

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.