
Untitled
By: a guest on
May 17th, 2012 | syntax:
None | size: 0.74 KB | hits: 12 | expires: Never
java regular expression
string example = "testXXXtest";
string result = example.substring(4,7);
Pattern pattern = Pattern.compile(".{4}(.{3}).*");
Matcher matcher = pattern.matcher("testXXXtest");
matcher.matches();
String whatYouNeed = matcher.group(1);
yourString.substring(4,7);
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Example {
public static void main(String[] args) {
String text = "This is a testWithSomeDataInBetweentest.";
Pattern p = Pattern.compile("test([A-Za-z0-9]*)test");
Matcher m = p.matcher(text);
if (m.find()) {
System.out.println("Matched: " + m.group(1));
} else {
System.out.println("No match.");
}
}
}
Matched: WithSomeDataInBetween