Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 17th, 2012  |  syntax: None  |  size: 0.74 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. java regular expression
  2. string example = "testXXXtest";
  3. string result = example.substring(4,7);
  4.        
  5. Pattern pattern = Pattern.compile(".{4}(.{3}).*");
  6. Matcher matcher = pattern.matcher("testXXXtest");
  7. matcher.matches();
  8. String whatYouNeed = matcher.group(1);
  9.        
  10. yourString.substring(4,7);
  11.        
  12. import java.util.regex.Pattern;
  13. import java.util.regex.Matcher;
  14.  
  15. public class Example {
  16.   public static void main(String[] args) {
  17.     String text = "This is a testWithSomeDataInBetweentest.";
  18.     Pattern p = Pattern.compile("test([A-Za-z0-9]*)test");
  19.     Matcher m = p.matcher(text);
  20.     if (m.find()) {
  21.       System.out.println("Matched: " + m.group(1));
  22.     } else {
  23.       System.out.println("No match.");
  24.     }
  25.   }
  26. }
  27.        
  28. Matched: WithSomeDataInBetween