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.
    var dailybugle = "Spider-Man Menaces City!";

    //Regex muss gesamten String untersuchen
    var regex = /spider[- ]?man/i;

    if (dailybugle.search(regex)) {
      //hier passiert etwas
    }
Listing 1.25 Einfaches Matching
///Datumsangaben in Formaten wie MM/DD/YYYY,
///MM-DD-YY ... erkennen
    var date = "12/30/1969";
    var p =
new RegExp
      ("^(\\d\\d)[-/](\\d\\d)[-/](\\d\\d(?:\\d\\d)?)$");

    var result = p.exec(date);
    if (result != null) {
      var monat = result[1];
      var tag   = result[2];
      var jahr  = result[3];
Listing 1.26 Matching- und Capture-Gruppe
//<br> XHTML-konform in <br /> umwandeln
    String text = "Hallo Welt! <br>";

    var pattern = /<br>/ig;

    test.replace(pattern, "<br />");
Listing 1.27 Einfache Substitution
//urlify ...

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