In Java, you can use regular expressions to extract special strings from a string.
You can extract the entire string that matches the expression, or you can extract only a portion of the string.
See the following code for details:
Import java. util. RegEx. matcher;
Import java. util. RegEx. pattern;
Public class testpatternfind {
Public static void main (string [] ARGs ){
String teststring = "xxxxxxx1234xxxxxxx5678xxxxx12xxx1xxx ";
Matcher = pattern. Compile ("// D +"). matcher (teststring );
While (matcher. Find ()){
System. Out. println (teststring. substring (matcher. Start (), matcher. End ()));
}
String teststring2 = "$ {object. Property }";
Matcher matcher2 = pattern. compile ("^ // $ // {([A-Za-Z] [a-zA-Z0-9 //.] *) //} $ "). matcher (teststring2 );
If (matcher2.matches ()){
System. Out. println (matcher2.group (0); // capture the entire matched string
System. Out. println (matcher2.group (1); // The string that matches the () part of the regular expression in the matched string.
}
}
}