Blog for the first time the essay was dedicated to the regular expression.
one: In Java introduced after JDK1.4, all the regular supported classes are defined in the Java.util.regex package . two: Regular tag: All the tags that can be used are in Java.unti.regex. The pattern class is defined inside. 1, "single" describes a character
- X: Represents a character consisting of x;
- \ \: Matches the escape character "\";
- \ t: Description tab "\ T";
- \ n: Matches line break "\ n";
2, "single" describes a range
- [ABC]: The expression may be any of the letters A, B, C;
- [^ABC]: Indicates that it is not a letter A, B, c any one;
- [0-9]: Any number representing 0 to 9;
- [A-za-z]: denotes any single letter, not case-sensitive;
- [A-Z]: denotes any of the lowercase letters;
- [A-Z]: represents any of the uppercase letters.
3, "single" Simplified expression
- “.” : Represents any one character, while \ \. means "." )
- \d: Equivalent to [0-9], indicating any one digit;
- \d: Equivalent to [^0-9], representing any one non-digit;
- \s: denotes any one whitespace character, possibly a space, \ t, \ n;
- \s: Denotes any one non-whitespace character;
- \w: Equivalent to [a-za-z_0-9], which is composed of letters, numbers and underscores;
- \w: Equivalent to [^a-za-z_0-9].
4, boundary matching (not in Java, JS must be used)
- ^: expression of the beginning of the regular;
- $: Indicates the end of the regular.
5, the quantity expression (can be used when repeated appearance)
- The regular? : Indicates that this regular match can occur 0 or 1 times;
- Regular +: Indicates that this regular match appears 1 or more times;
- Regular *: Indicates that this regular match appears 0 times, 1 times or more;
- Regular {n}: Indicates that this regular match occurs exactly n times;
- Regular {N,}: Indicates that this regular match appears n or n times;
- Regular {N,m}: Indicates the occurrence of n~m times.
6. Logical Operation
- Regular a regular B: regular A matches the regular B immediately after the match is finished;
- Regular a| regular B: Regular A or regular B has a set of satisfied;
- (regular): multiple regular as a set of processes, you can set the number of occurrences of this set alone.
specific usage of regular expressions reference to: String class support for regular expressions
Common Regular Expressions