O'Reilly logo

Reguläre Ausdrücke kurz & gut, 2nd Edition by Tony Stubblebine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Beispiele

//Suche nach Spider-Man, Spiderman, SPIDER-MAN usw.
public class StringRegexTest {
  public static void main(String[  ] args) throws Exception {
    String dailybugle = "Spider-Man Menaces City!";

    //Regex muss gesamten String prüfen.
    String regex = "(?i).*spider[- ]?man.*";

    if (dailybugle.matches(regex)) {
      System.out.println("Treffer: " + dailyBugle);
    }
  }
}
Listing 1.5 Einfaches Matching
//Datumsangaben in Formaten wie MM/DD/YYYY, //MM-DD-YY ... erkennen import java.util.regex.*; public class MatchTest { public static void main(String[ ] args) throws Exception { String date = "12/30/1969"; Pattern p = Pattern.compile("^(\\d\\d)[-/](\\d\\d)[-/](\\d\\d(?:\\d\\d)?)$"); Matcher m = p.matcher(date); if (m.find( )) { String monat = m.group(1); String ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required