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

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

Java
\p{Lower}   A lower-case alphabetic character: [a-z]
\p{Upper}   An upper-case alphabetic character:[A-Z]
\p{ASCII}   All ASCII:[\x00-\x7F]
\p{Alpha}   An alphabetic character:[\p{Lower}\p{Upper}]
\p{Digit}   A decimal digit: [0-9]
\p{Alnum}   An alphanumeric character:[\p{Alpha}\p{Digit}]
\p{Punct}   Punctuation: One of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ \p{Graph} A visible character: [\p{Alnum}\p{Punct}] \p{Print} A printable character: [\p{Graph}\x20] \p{Blank} A space or a tab: [ \t] \p{Cntrl} A control character: [\x00-\x1F\x7F] \p{XDigit} A hexadecimal digit: [0-9a-fA-F] \p{Space} */ 
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);        
    }
原文链接:https://www.f2er.com/regex/360315.html

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