正则表达式,oracle部分匹配转java的全部匹配

前端之家收集整理的这篇文章主要介绍了正则表达式,oracle部分匹配转java的全部匹配前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
/*
    Oracle:    
@H_301_2@[:alnum:@H_301_2@]   All alphanumeric characters
@H_301_2@[:alpha:@H_301_2@]   All alphabetic characters
@H_301_2@[:blank:@H_301_2@]   All blank space characters.
@H_301_2@[:cntrl:@H_301_2@]   All control characters (nonprinting)
@H_301_2@[:digit:@H_301_2@]   All numeric digits
@H_301_2@[:graph:@H_301_2@]   All @H_301_2@[:punct:@H_301_2@],@H_301_2@[:upper:@H_301_2@],@H_301_2@[:lower:@H_301_2@],and @H_301_2@[:digit:@H_301_2@] characters.
@H_301_2@[:lower:@H_301_2@]   All lowercase alphabetic characters
@H_301_2@[:print:@H_301_2@]   All printable characters
@H_301_2@[:punct:@H_301_2@]   All punctuation characters
@H_301_2@[:space:@H_301_2@]   All space characters (nonprinting)
@H_301_2@[:upper:@H_301_2@]   All uppercase alphabetic characters
@H_301_2@[:xdigit:@H_301_2@]

Java
\p@H_301_2@{Lower@H_301_2@}   A lower-case alphabetic character: @H_301_2@[a-z@H_301_2@]
\p@H_301_2@{Upper@H_301_2@}   An upper-case alphabetic character:@H_301_2@[A-Z@H_301_2@]
\p@H_301_2@{ASCII@H_301_2@}   All ASCII:@H_301_2@[\x00-\x7F@H_301_2@]
\p@H_301_2@{Alpha@H_301_2@}   An alphabetic character:@H_301_2@[\p@H_301_2@{Lower@H_301_2@}\p@H_301_2@{Upper@H_301_2@}@H_301_2@]
\p@H_301_2@{Digit@H_301_2@}   A decimal digit: @H_301_2@[0-9@H_301_2@]
\p@H_301_2@{Alnum@H_301_2@}   An alphanumeric character:@H_301_2@[\p@H_301_2@{Alpha@H_301_2@}\p@H_301_2@{Digit@H_301_2@}@H_301_2@]
\p@H_301_2@{Punct@H_301_2@}   Punctuation: One of !"@H_301_2@#$%@H_301_2@&'()*+,-./:;<=>?@@H_301_2@[\]^_`@H_301_2@{|@H_301_2@}@H_301_2@~ \p@H_301_2@{Graph@H_301_2@} A visible character: @H_301_2@[\p@H_301_2@{Alnum@H_301_2@}\p@H_301_2@{Punct@H_301_2@}@H_301_2@] \p@H_301_2@{Print@H_301_2@} A printable character: @H_301_2@[\p@H_301_2@{Graph@H_301_2@}\x20@H_301_2@] \p@H_301_2@{Blank@H_301_2@} A space or a tab: @H_301_2@[ \t@H_301_2@] \p@H_301_2@{Cntrl@H_301_2@} A control character: @H_301_2@[\x00-\x1F\x7F@H_301_2@] \p@H_301_2@{XDigit@H_301_2@} A hexadecimal digit: @H_301_2@[0-9a-fA-F@H_301_2@] \p@H_301_2@{Space@H_301_2@} */ 
private static String[][] oracle2javaPatterns = 
            new String[][] {
                {"[[:alnum:]]","[:alnum:]","\\p{Alnum}"},{"[^[:alpha:]]","[^:alpha:]","[^a-zA-Z\\u4E00-\\u9FFF]"},{"[[:alpha:]]","[:alpha:]","[a-zA-Z\\u4E00-\\u9FFF]"},{"[[:blank:]]","[:blank:]","\\p{Blank}"},{"[[:cntrl:]]","[:cntrl:]","\\p{Cntrl}"},{"[[:digit:]]","[:digit:]","\\p{Digit}"},{"[[:graph:]]","[:graph:]","\\p{Graph}"},{"[[:lower:]]","[:lower:]","\\p{Lower}"},{"[[:print:]]","[:print:]","\\p{Print}"},{"[[:punct:]]","[:punct:]","\\p{Punct}"},{"[[:space:]]","[:space:]","\\p{Space}"},{"[[:upper:]]","[:upper:]","\\p{Upper}"},{"[[:xdigit:]]","[:xdigit:]","\\p{Xdigit}"}           
            };

    public static String oraclePattern2javaPattern(String patternValue) {
        for (int i = 0; i < oracle2javaPatterns.length; i++) {
            String[] patterns = oracle2javaPatterns[i];
            String opattern0 = patterns[0];
            String opattern1 = patterns[1];
            String jpattern = patterns[2];
            if (patternValue.contains(opattern0)) {
                patternValue = patternValue.replace(opattern0,jpattern);
            }
            if (patternValue.contains(opattern1)) {
                patternValue = patternValue.replace(opattern1,jpattern);
            }
        }
        return patternValue;
    } 

    private void oraclePattern2javaPattern() {
        if (!patternValue.startsWith("^")) {
            patternValue = ".*" + patternValue;
        }
        if (!patternValue.endsWith("$")) {
            patternValue = patternValue + ".*";
        }
        this.patternValue = oraclePattern2javaPattern(patternValue);        
    }

猜你在找的正则表达式相关文章