The following features are given in the Java Java.util.regex.Pattern class:
Predefined character classes |
. |
Any character (may or may not match the line terminator) |
/d |
Number: [0-9] |
/d |
Non-digit: [^0-9] |
/s |
whitespace characters: [/t/n/x0b/f/r] |
/S |
Non-whitespace characters: [^/s] |
/w |
Word characters: [a-za-z_0-9] |
/w |
Non-word characters: [^/w] |
Greedy quantity Word |
X? |
X, not once or once |
x* |
X, 0 or more times |
x+ |
X, one or more times |
X{n} |
X, exactly n times |
X{n,} |
X, at least n times |
X{N,M} |
X, at least n times, but not more than m times |
The function of the following example replaces all whitespace characters in a string with/T, and then split
public class Spacereplace {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
String s = "1 3 2 4 we dads Daj";
System.out.println (s);
S=s.replaceall ("//s+", "T");
String [] sa = S.split ("/t");
System.out.println (s);
}
}