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.
namespace Regex_PocketRef
{
  using System.Text.RegularExpressions;

  class SimpleMatchTest
  {
    static void Main(  )
    {
      string dailybugle = "Spider-Man Menaces City!";

      string regex = "spider[- ]?man";

    if (Regex.IsMatch(dailybugle, regex, RegexOptions.IgnoreCase)) {
      //hier passiert etwas
    }
  }
}
Listing 1.9 Einfaches Matching
//Datumsangaben in Formaten wie MM/DD/YYYY, MM-DD-YY ...
//mittels System.Text.RegularExpressions erkennen

class MatchTest
{
  static void Main(  )
  {
    string date = "12/30/1969";
Regex r = new Regex( @"^(\d\d)[-/](\d\d)[-/](\d\d(?:\d\d)?)$" ); Match m = r.Match(date); if (m.Success) { string monat = m.Groups[1].Value; string tag = m.Groups[2].Value; string jahr = m.Groups[3].Value; ...

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