{"id":1058,"date":"2017-07-24T13:29:15","date_gmt":"2017-07-24T11:29:15","guid":{"rendered":"https:\/\/abchaus.synology.me\/wordpress\/?p=1058"},"modified":"2017-07-24T13:29:15","modified_gmt":"2017-07-24T11:29:15","slug":"regex-auf-die-schnelle-erklrt","status":"publish","type":"post","link":"https:\/\/abchaus.synology.me\/wordpress\/blog\/2017\/07\/24\/regex-auf-die-schnelle-erklrt\/","title":{"rendered":"RegEx auf die schnelle erkl&auml;rt"},"content":{"rendered":"<p align=\"justify\">Da gibt es eine wirklich nette Seite, wo das Thema kurz und knackig erl\u00e4utert wird. Sollte man als Anf\u00e4nger mal gelesen haben. <a title=\"https:\/\/danielfett.de\/de\/tutorials\/tutorial-regulare-ausdrucke\/\" href=\"https:\/\/danielfett.de\/de\/tutorials\/tutorial-regulare-ausdrucke\/\">https:\/\/danielfett.de\/de\/tutorials\/tutorial-regulare-ausdrucke\/<\/a><\/p>\n<p align=\"justify\">Hier noch ein kleiner Auszug als Vorgeschmack:<\/p>\n<p class=\"intro\" style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">&#8222;Regul\u00e4re Ausdr\u00fccke&#8220; sind eine Art Sprache, die beim Programmieren f\u00fcr diverse Probleml\u00f6sungen verwendet werden kann, insbesondere dann, wenn es darum geht, Zeichenketten (Strings) zu bearbeiten, zu pr\u00fcfen oder in ihnen etwas zu suchen.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Und weil der Name &#8222;Regul\u00e4re Ausdr\u00fccke&#8220; etwas unhandlich ist, hei\u00dfen die &#8222;Regular Expressions&#8220; auch oft einfach nur &#8222;RegEx(en)&#8220;.<\/p>\n<h2 id=\"Einfhrung\" style=\"color: rgb(55, 90, 127); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 36px; font-style: normal; font-weight: 300; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Einf\u00fchrung<\/h2>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Hier gibts ein kleines Tutorial zu diesen esoterisch anmutenden aber unglaublich m\u00e4chtigen Zeichenketten, die beim unbedarften Betrachter Assoziationen eines kleinen Kindes und dessen ersten Versuchen an der Tastatur ausl\u00f6sen.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\"><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">Was sind regul\u00e4re Ausdr\u00fccke?<\/strong><span>&nbsp;<\/span>Wie gesagt, k\u00f6nnen mit regul\u00e4ren Ausdr\u00fccken Zeichenketten auf eine bestimmte Zusammensetzung gepr\u00fcft werden, wie dies z.B. bei Anwendungen wichtig ist, die Eingaben eines Benutzers erwarten.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Beispiele:<\/p>\n<ul style=\"color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; margin-top: 0px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">\n<li style=\"box-sizing: border-box;\">Schulnote<\/li>\n<li style=\"box-sizing: border-box;\">Postleitzahl<\/li>\n<li style=\"box-sizing: border-box;\">E-Mail-Adresse<\/li>\n<li style=\"box-sizing: border-box;\">Bestellnummern<\/li>\n<\/ul>\n<h3 id=\"KonkreteAnwendung\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Konkrete Anwendung<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Popul\u00e4re Stellen, an denen man auf regul\u00e4re Ausdr\u00fccke sto\u00dfen kann und an denen du dieses Wissen anbringen kannst:<\/p>\n<ul style=\"color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; margin-top: 0px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">\n<li style=\"box-sizing: border-box;\">Web-Anwendungen (z.B. in PHP, Perl)<\/li>\n<li style=\"box-sizing: border-box;\">Unix-Skripte<\/li>\n<\/ul>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Im Folgenden wird davon ausgegangen, dass du eine entsprechende Stelle vorliegen hast und dich bereits informiert hast, wie regul\u00e4re Ausdr\u00fccke in der Umgebung deiner Wahl verwendet werden. In PHP geschieht dies z.B. mit den Funktionen<span>&nbsp;<\/span><a style=\"transition:color 0.2s; color: rgb(55, 90, 127); text-decoration: none; box-sizing: border-box; background-color: transparent;\" href=\"http:\/\/www.php.net\/preg_match\" target=\"_blank\">preg_match<\/a><span>&nbsp;<\/span>(Pr\u00fcfen von Strings, finden von Zeichenketten) und<span>&nbsp;<\/span><a style=\"transition:color 0.2s; color: rgb(55, 90, 127); text-decoration: none; box-sizing: border-box; background-color: transparent;\" href=\"http:\/\/www.php.net\/preg_replace\" target=\"_blank\">preg_replace<\/a><span>&nbsp;<\/span>(Ersetzen von Zeichenketten).<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Am Besten testest du deinen Ausdruck zuerst &#8222;auf dem Trockenen&#8220;. Dazu kannst du ein Onlinetool wie<span>&nbsp;<\/span><a class=\" \" style=\"transition:color 0.2s; color: rgb(55, 90, 127); text-decoration: none; box-sizing: border-box; background-color: transparent;\" href=\"https:\/\/regex101.com\/\">regex 101<\/a> oder den<span>&nbsp;<\/span><a style=\"transition:color 0.2s; color: rgb(55, 90, 127); text-decoration: none; box-sizing: border-box; background-color: transparent;\" href=\"http:\/\/www.weitz.de\/regex-coach\/\" target=\"_blank\">Regex-Coach<\/a><span>&nbsp;<\/span>benutzen.<\/p>\n<h3 id=\"GuterStil\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Guter Stil<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Oft wirst du feststellen, dass es zu einem Problem viele verschiedene L\u00f6sungen gibt. Dabei stehen sich dann gegen\u00fcber<\/p>\n<ul style=\"color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; margin-top: 0px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">\n<li style=\"box-sizing: border-box;\"><span class=\"div\" style=\"box-sizing: border-box;\"><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">Eine<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">genaue<\/em><span>&nbsp;<\/span>L\u00f6sung und eine<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">allgemeinere<\/em>.<\/strong><span>&nbsp;<\/span>Besteht die Gefahr, dass die genaue L\u00f6sung zu &#8222;restriktiv&#8220; ist (und damit vielleicht ein Benutzer frustriert aufgibt, wenn seine richtige Eingabe nicht akzeptiert wird), nimm lieber die allgemeine. Ist das Problem aber sehr &#8222;eindeutig&#8220;, nimm lieber die genaue.<\/span><\/li>\n<li style=\"box-sizing: border-box;\"><span class=\"div\" style=\"box-sizing: border-box;\"><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">Eine<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">genaue<\/em><span>&nbsp;<\/span>L\u00f6sung und eine<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">schnelle<\/em>.<\/strong><span>&nbsp;<\/span>Lange regul\u00e4re Ausdr\u00fccke k\u00f6nnen viel Zeit f\u00fcr die Verarbeitung in Anspruch nehmen. Auch hier musst du abw\u00e4gen, was dir wichtiger ist. Es k\u00f6nnte Benutzer \u00e4rgern, wenn die Pr\u00fcfung einer Eingabe sehr lange dauert.<\/span><\/li>\n<li style=\"box-sizing: border-box;\"><span class=\"div\" style=\"box-sizing: border-box;\"><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">Eine<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">einfache<\/em><span>&nbsp;<\/span>L\u00f6sung und eine<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">&#8222;elegante&#8220;<\/em>.<\/strong><span>&nbsp;<\/span>Du kannst in 10 Zeichen ausdr\u00fccken, was andere nicht in 60 schaffen? Prima, aber denk dran dass du vielleicht sp\u00e4ter nochmal was \u00e4ndern willst! Und das kann schwerer werden, als man denkt. Daher nimm lieber die einfachere Variante oder kommentiere komplizierte Ausdr\u00fccke.<\/span><\/li>\n<\/ul>\n<h3 id=\"Probleme\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Probleme<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Wenn dein regul\u00e4rer Ausdruck Probleme macht, du dir aber ziemlich sicher bist dass er richtig ist, schau dir zun\u00e4chst mal weiter unten die<span>&nbsp;<\/span><a style=\"transition:color 0.2s; color: rgb(55, 90, 127); text-decoration: none; box-sizing: border-box; background-color: transparent;\" href=\"https:\/\/danielfett.de\/de\/tutorials\/tutorial-regulare-ausdrucke\/#SpezielleZeichenWeitereZeichen\">Sonderzeichen<\/a><span>&nbsp;<\/span>an und was man mit ihnen machen muss, um sie zu benutzen. Dabei sind Sonderzeichen schon so &#8222;banale&#8220; Sachen wie ein Punkt.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Au\u00dferdem solltest du ihn dringend im o.g. RegEx-Coach testen! Dieser f\u00f6rdert manchmal geradezu unglaubliche irregul\u00e4re Verhaltensweisen zutage \ud83d\ude09<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Dann darfst du als n\u00e4chstes Google benutzen \ud83d\ude09 Da findet man sehr viele Informationen, viele Vorlagen um diverse Problemstellungen regul\u00e4r auszudr\u00fccken und auch die Google-Groups sind immer hilfreich.<\/p>\n<h3 id=\"Konventionen\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Konventionen<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">In diesem Tutorial werden folgende Farben f\u00fcr Texte (Strings) verwendet:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">Regul\u00e4rer Ausdruck, den du theoretisch so verwenden kannst, mit<br style=\"box-sizing: border-box;\"><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">markierten neuen Teilen<\/span><br style=\"box-sizing: border-box;\"><span class=\"wrong\" style=\"color: rgb(153, 0, 0); box-sizing: border-box;\">Absichtlich fehlerhafter Code<\/span><\/code>\u00d6fters verwende ich mal den Programmierern nicht fremden &#8222;String&#8220; (ich spar mir den Unterw\u00e4sche-Witz) f\u00fcr ein Textst\u00fcck. Au\u00dferdem gilt: ein Ausdruck &#8222;trifft&#8220; = &#8222;beschreibt einen Text genau&#8220; = &#8222;erledigt die gew\u00fcnschte Funktion&#8220; = &#8222;matcht&#8220; = &#8222;frisst (etwas)&#8220;<\/p>\n<h2 id=\"EinfacheAusdrcke\" style=\"color: rgb(55, 90, 127); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 36px; font-style: normal; font-weight: 300; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Einfache Ausdr\u00fccke<\/h2>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\"><\/p>\n<h3 id=\"EinElementigeregulreAusdrcke\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Ein-Elementige regul\u00e4re Ausdr\u00fccke<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Fangen wir mal klein an. Wir wollen pr\u00fcfen, ob eine Eingabe einer Schulnote von 1-6 entspricht.<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">[123456]<\/span><\/code>erledigt das f\u00fcr uns. Du siehst: in eckigen Klammern folgt eine Auflistung von Zeichen, die erlaubt sind. Insgesamt steht der gesamte geklammerte Ausdruck aber nur f\u00fcr ein Zeichen: 1<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">oder<\/em><span>&nbsp;<\/span>2<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">oder<\/em><span>&nbsp;<\/span>&#8230;<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">oder<\/em><span>&nbsp;<\/span>6.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Da unsere Zahlen von 1 bis 6 so sch\u00f6n aufeinanderfolgen, k\u00f6nnen wir auch schreiben<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">[1-6]<\/span><\/code>was die Sache etwas \u00fcbersichtlicher macht. Genau so k\u00f6nnte man z.b. pr\u00fcfen, ob eine Eingabe einem Gleis auf einem Bahnhof entspricht:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">[1-9]<\/span><\/code>f\u00fcr einen Bahnhof mit 9 Gleisen. Auf unserem Bahnhof sei heute Gleis 4 gesperrt, also als Eingabe nicht erlaubt:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[1-3<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">5-9<\/span>]<\/code>Wir haben den Eingabebereich also aufgeteilt in zwei Bereiche 1-3 und 5-9. Du siehst: Die beiden Bereiche werden einfach hintereinander geschrieben. Das ist am Anfang gew\u00f6hnungsbed\u00fcrftig (intuitiv m\u00f6chte man vielleicht ein Leerzeichen machen), aber das wird uns noch \u00f6fter begegnen.<\/p>\n<h3 id=\"MehrelementigeregulreAusdrcke\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Mehrelementige regul\u00e4re Ausdr\u00fccke<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Was ist, wenn auf unserem Bahnhof jetzt angebaut wird? Sagen wir, er wird auf 12 Gleise erweitert:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"wrong\" style=\"color: rgb(153, 0, 0); box-sizing: border-box;\">[1-12]<\/span><\/code>(Gleis 4 sei wieder ge\u00f6ffnet \ud83d\ude09 ).<span>&nbsp;<\/span><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">Aber Vorsicht, hier ist ein Fehler drin!<\/strong><\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Wie oben erw\u00e4hnt, steht der<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">gesamte<\/em><span>&nbsp;<\/span>Ausdruck in den eckigen Klammern nur f\u00fcr<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">ein<\/em><span>&nbsp;<\/span>Zeichen. &#8222;12&#8220; enth\u00e4lt aber zwei Zeichen. Der Code oben wird nicht funktionieren: Er bedeutet &#8222;1 bis 1&#8220;<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">oder<\/em><span>&nbsp;<\/span>&#8222;2&#8220;. Den Umgang mit Bahnh\u00f6fen mit mehr als 9 Gleisen demonstrieren wir sp\u00e4ter.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">F\u00fcr den Moment wollen wir etwas anderes Pr\u00fcfen: Bahnsteige 1-9 haben noch jeweils Abschnitt &#8222;a&#8220; und &#8222;b&#8220;. Wir wollen also auf 1a,1b,2a,&#8230;,9a,9b pr\u00fcfen:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[1-9]<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">[ab]<\/span><\/code>Will hei\u00dfen: Eine Zahl 1-9 gefolgt von einem Buchstaben a oder b.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Mehrere rechteckige Klammern entsprechen also mehreren Zeichen. Soll ein Ausdruck mehrere Zeichen beschreiben, werden diese einfach hintereinander gehangen. Dann wird die Eingabe von links nach rechts mit deinem Ausdruck verglichen.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Selbstverst\u00e4ndlich m\u00fcssen auch nicht immer alle Buchstaben aufgef\u00fchrt werden:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[1-9][<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">a-d<\/span>]<\/code>trifft jetzt auch z.B. 4d.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Zu beachten ist, dass Gro\u00df- und Kleinschreibung getrennt behandelt wird. Eine sinnvolle Erweiterung w\u00e4re also z.B.<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[1-9][a-d<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">A-D<\/span>]<\/code><\/p>\n<h3 id=\"Optionen\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Optionen<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Schauen wir uns die Eingabe einer Hausnummer an. Diese k\u00f6nnen aus einer oder mehreren (bis zu 3) Ziffern bestehen und ein a-z am Ende haben. M\u00fcssen aber nicht.<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[1-9][0-9]<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">?<\/span>[0-9]<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">?<\/span>[a-z]<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">?<\/span><\/code>Das Fragezeichen hinter einem Element (und [1-9] ist<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">ein<\/em><span>&nbsp;<\/span>Element!) besagt: Das vorhergehende Element<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">kann<\/em><span>&nbsp;<\/span>vorkommen, muss aber nicht.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Der letzte Code hei\u00dft also: Eine Ziffer (1-9), optional zwei weitere Ziffern (0-9), optional ein Buchstabe.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Stellt man sich solch eine Konstruktion mit z.B. 10 Ziffern vor, kann man sich leicht ausmalen, dass sie schnell sehr lang wird. Daher gibt es eine andere Schreibweise, wenn man ein Element mehr als ein mal erlauben will:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">a<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">{1,3}<\/span>h<\/code>Trifft auf &#8222;ah&#8220; genau so wie auf &#8222;aaah&#8220;. Die Angabe in Klammern steht also f\u00fcr die {minimale, maximale} Anzahl an Zeichen. Daher k\u00f6nnen wir unsere Hausnummern auch so formulieren:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[1-9][0-9]<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">{0,2}<\/span>[a-z]?<\/code>und dann auch ohne Probleme f\u00fcr l\u00e4ngere Stra\u00dfen (USA \ud83d\ude09 ) umschreiben:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[1-9][0-9]<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">{1,4}<\/span>[a-z]?<\/code>erlaubt jetzt auch Hausnummern im f\u00fcnfstelligen Bereich, fordert aber mindestens eine zweistellige (beachte die \u00c4nderung vor dem Komma).<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Eine Konstruktion wie<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[0-9]<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">{5}<\/span><\/code>(also eine Klammer mit nur einer Angabe) verlangt eine genau x-malige Wiederholung des davorstehenden Ausdrucks. In unserem Fall 5 mal: Dieser regul\u00e4re Ausdruck w\u00e4re geeignet, um (deutsche) Postleitzahlen zu pr\u00fcfen.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Wir k\u00f6nne auch ein &#8222;mindestens&#8220; ausdr\u00fccken:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[0-9]<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">{3,}<\/span><\/code>fordert mindestens 3 Ziffern.<\/p>\n<h3 id=\"BeliebigeWiederholungen\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Beliebige Wiederholungen<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Bisher mussten wir immer wissen, wieviele Zeichen gefunden werden sollen. Es gibt aber durchaus F\u00e4lle, in denen sich ein Zeichen beliebig oft wiederholen darf.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Schauen wir uns die Pr\u00fcfung von Telefonnummern an. Wenn man einen regul\u00e4ren Ausdruck schreibt, empfiehlt es sich oft, zun\u00e4chst einmal zu notieren, auf was dieser alles treffen soll. Unsere Telefonnummern sollen von diesem Format sein d\u00fcrfen:<\/p>\n<ul style=\"color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; margin-top: 0px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">\n<li style=\"box-sizing: border-box;\">0651\/55541-36<\/li>\n<li style=\"box-sizing: border-box;\">0049 160 555678<\/li>\n<li style=\"box-sizing: border-box;\">0180.23.555.63<\/li>\n<\/ul>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Es k\u00f6nnen neben Zahlen also auch Bindestriche, Querstriche, Leerzeichen und Punkte vorkommen.<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">Ein<\/em>g\u00fcltiges Element w\u00e4re also<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"wrong\" style=\"color: rgb(153, 0, 0); box-sizing: border-box;\">[0-9\/. -]<\/span><\/code>(Also: Dieses<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">eine<\/em><span>&nbsp;<\/span>Zeichen besteht aus einer Zahl zwischen 0 und 9<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">oder<\/em><span>&nbsp;<\/span>einem Slash<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">oder<\/em><span>&nbsp;<\/span>einem Punkt<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">oder<\/em><span>&nbsp;<\/span>einem Leerzeichen<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">oder<\/em><span>&nbsp;<\/span>einem Minus.) Doch Vorsicht! Wie du siehst, kommen in den Klammern zwei Bindestriche vor: ein mal in einer speziellen Funktion, um einen Zahlenbereich anzudeuten und ein mal als &#8222;echter&#8220; Bindestrich, der so auftauchen darf. Um Verwechslungen auszuschlie\u00dfen m\u00fcssen wir letzteren maskieren, also zeigen dass er hier keine spezielle Funktion hat. Das geht mit einem vorangestellten Backslash:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[0-9\/.<span>&nbsp;<\/span><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">\\<\/span>-]<\/code>Und dann wollen wir ja noch mitteilen, dass diese Zeichen beliebig oft vorkommen d\u00fcrfen:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[0-9\/. \\-]<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">+<\/span><\/code>Das Plus bedeutet: ein oder mehrmals das davor befindliche Zeichen, also mindestens ein mal. Wollen wir auch eine leere Telefonnummer zulassen (der Mathematiker w\u00fcrde sagen: Die Nullnummer), so gibt es dazu ein anderes Zeichen:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[0-9\/. \\-]<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">*<\/span><\/code>trifft jetzt auch auf &#8222;&#8220; (leere Zeichenkette) und nat\u00fcrlich unsere Telefonnummern.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Dieser Ausdruck ist jetzt nat\u00fcrlich ein sehr allgemeiner Ausdruck (siehe die Diskussion oben). Er erlaubt auch Telefonnummern, die offensichtlich nicht korrekt sind, wie<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">--..\/\/123<\/code>M\u00f6chte man das weiter einschr\u00e4nken, muss man einen komplizierteren Ausdruck entwickeln.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Also nochmal zusammengefasst: Das + steht f\u00fcr eine mindestens einmalige Wiederholung. * hei\u00dft: keinmal oder beliebig oft.<\/p>\n<h3 id=\"Platzhalter\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Platzhalter<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Gehen wir zu einem anderen Beispiel \u00fcber: Wir m\u00f6chten in einer Bibliothek nach einem Autor suchen, wissen aber nicht, ob er evtl. einen zweiten Vornamen hat. Nach dem Vornamen k\u00f6nnen also<span>&nbsp;<\/span><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">beliebige Zeichen<\/strong><span>&nbsp;<\/span>kommen und danach dann erst der Nachname. Eine m\u00f6gliche L\u00f6sung sieht so aus:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">Marius<span>&nbsp;<\/span><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">.<\/span>*Osterhase<\/code>Die im Einzelnen bedeutet: &#8222;Marius&#8220;, danach ein Leerzeichen gefolgt von einem beliebigen Zeichen (daf\u00fcr steht der Punkt!) beliebig oft (also evtl. auch gar keins) und anschlie\u00dfend der Nachname. Das trifft auf &#8222;Marius Osterhase&#8220; genau so wie auf &#8222;Marius M\u00fcller Osterhase&#8220;.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Genau so kann man dem Punkt nat\u00fcrlich auch ein Plus folgen lassen, um mindestens ein beliebiges Zeichen zu fordern.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Der Punkt &#8222;frisst&#8220; normalerweise zwar fast alles, aber keine Zeilenumbr\u00fcche. Wie du ihn dazu bringst, findest du unter<span>&nbsp;<\/span><a style=\"transition:color 0.2s; color: rgb(55, 90, 127); text-decoration: none; box-sizing: border-box; background-color: transparent;\" href=\"https:\/\/danielfett.de\/de\/tutorials\/tutorial-regulare-ausdrucke\/#Modifikatoren\">Modifikatoren<\/a>.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Dem &#8222;aufmerksamen Leser&#8220; wird nicht entgangen sein, dass wir oben auch schon einen Punkt hatten, und zwar innerhalb der eckigen Klammern. Wie bei<span>&nbsp;<\/span><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">vielen<\/strong>, aber nicht allen Sonderzeichen m\u00fcssen diese zwar au\u00dferhalb von eckigen Klammern als solche maskiert werden (Backslash davor), aber nicht innerhalb.<\/p>\n<h3 id=\"Zeichenklassennegieren\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Zeichenklassen negieren<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Angenommen wir w\u00fcssten den zweiten Vornamen des Autors nicht genau, aber k\u00f6nnen uns daran erinnern, dass er kein q und kein z enth\u00e4lt. Auch kein Problem:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">Marius<span>&nbsp;<\/span><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">[^<\/span>qz<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">]+<\/span><span>&nbsp;<\/span>Osterhase<\/code>verlangt nach einem zweiten Vornamen (deswegen das Plus) und l\u00e4sst dazu ein beliebiges Zeichen zu, das<span>&nbsp;<\/span><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">nicht<\/strong><span>&nbsp;<\/span>q oder z ist. Das ^ negiert also eine Zeichenklasse und gilt genau bis zur schlie\u00dfenden Klammer.<\/p>\n<h3 id=\"Klammern\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Klammern<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Klammern k\u00f6nnen dazu benutzt werden, l\u00e4ngere Ausdr\u00fccke zu einem Element zusammenzufassen und es damit zu erm\u00f6glichen, das oben gelernte auch auf Teilausdr\u00fccke anzuwenden:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">Marius<span>&nbsp;<\/span><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">(<\/span>M\u00fcller<span>&nbsp;<\/span><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">)?<\/span>Osterhase<\/code>trifft genau auf &#8222;Marius M\u00fcller Osterhase&#8220; oder &#8222;Marius Osterhase&#8220; und auf nichts anderes: Das Fragezeichen bezieht sich &#8211; dank der Klammern &#8211; auf den kompletten zweiten Vornamen und das folgende Leerzeichen.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Ebenso l\u00e4sst sich schreiben:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">Ba<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">(<\/span>na<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">)*<\/span>ne<\/code>Was jetzt sowohl f\u00fcr dieses gelbe Ding als auch z.B. f\u00fcr &#8222;Banananane&#8220; steht. Auch hier l\u00e4sst sich die Notation mit den geschweiften Klammern anwenden:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">Ba<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">(<\/span>na<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">){2,5}<\/span>ne<\/code>was jetzt nat\u00fcrlich eine entsprechend andere Bedeutung hat.<\/p>\n<h3 id=\"Alternativen\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Alternativen<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Mit Klammern kann man aber auch noch andere Sachen machen, z.B. Alternativen zu einem Teilausdruck angeben:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">Das Wetter ist<span>&nbsp;<\/span><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">(<\/span>toll<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">|<\/span>richtig schlecht<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">)<\/span><\/code>In diesem Beispiel d\u00fcrfen als letzte Worte &#8222;toll&#8220;<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">oder<\/em><span>&nbsp;<\/span>&#8222;richtig schlecht&#8220; vorkommen, aber nicht beide.<\/p>\n<h3 id=\"Modifikatoren\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Modifikatoren<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">In allen RegEx-Varianten kannst du sogenannte Modifikatoren setzen und damit das genaue Verhalten des Ausdrucks kontrollieren. In Java kannst du dies z.B. bei der Konstruktion eines matcher-Objektes erledigen, bei PHP hat ein regul\u00e4rer Ausdruck immer die Syntax<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[Begrenzungszeichen][RegEx][Begrenzungszeichen][Modifikator(en)]<\/code>also z.B.<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">\/(Mein|Ausdruck)\/im<\/code>Dabei sind die Slashes die Begrenzungszeichen (andere sind hier denkbar, z.B. ~), und &#8222;i&#8220; und &#8222;m&#8220; in diesem Fall Modifikatoren. G\u00e4ngige Modifikatoren sind unter anderem:<\/p>\n<ul style=\"color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; margin-top: 0px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">\n<li style=\"box-sizing: border-box;\"><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">i<\/strong><span>&nbsp;<\/span>Case-Insensitivity (die Nichtbeachtung von Gro\u00df- und Kleinschreibung) einschalten<\/li>\n<li style=\"box-sizing: border-box;\"><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">s<\/strong><span>&nbsp;<\/span>Punkt wird multilinef\u00e4hig: Der Punkt frisst auch Zeilenumbr\u00fcche, dies ist standardm\u00e4\u00dfig nicht so.<\/li>\n<li style=\"box-sizing: border-box;\"><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">m<\/strong><span>&nbsp;<\/span>Zeilenmodus: Die Zeichen ^ und $ matchen auch auf Zeilenanf\u00e4nge bzw. -enden. Ohne den Modifikator passen sie nur auf Anfang und Ende der gesamten Zeichenkette.<\/li>\n<\/ul>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Modifikatoren beziehen sich immer auf den ganzen Ausdruck und sind daher eine leicht \u00fcbersehene Fehlerquelle.<\/p>\n<h2 id=\"KompliziertereAusdrcke\" style=\"color: rgb(55, 90, 127); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 36px; font-style: normal; font-weight: 300; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Kompliziertere Ausdr\u00fccke<\/h2>\n<h3 id=\"Verschachtelungen\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Verschachtelungen<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Selbstverst\u00e4ndlich d\u00fcrfen auch diverse Klammern ineinander geschachtelt werden, wie z.B. in folgendem Ausdruck:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">(VW (Golf|Polo)|Fiat (Punto|Panda))<\/code>welcher auf &#8222;VW Golf&#8220;, &#8222;VW Polo&#8220;, &#8222;Fiat Punto&#8220; und &#8222;Fiat Panda&#8220; trifft. Dies erm\u00f6glich zwar recht kurze Ausdr\u00fccke f\u00fcr lange Zeichenketten, kann aber auch viel Zeit zur Verarbeitung in Anspruch nehmen.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Genau so lassen sich auch diese Alternativen wiederholen:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">(10|01)<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">+<\/span><\/code>Beschreibt eine Folge aus Nullen und Einsen, in der maximal 2 Nullen oder Einsen aufeinander folgen. (Falls das jetzt nicht direkt klar wird: einfach mal \u00fcberlegen, was man aus &#8222;10&#8220; und &#8222;01&#8220; zusammensetzen kann.)<\/p>\n<h3 id=\"GierigeAusdrcke\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Gierige Ausdr\u00fccke<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Ein Beispiel aus der Praxis: Der folgende, etwas l\u00e4ngerer Code soll uns aus einer HTML-Datei die Links bzw. deren Zieladressen heraussuchen. Ein Link in einem HTML-Quellcode hat i.d.R. ein Format wie dieses:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">&lt;a href=\"[...Zieladresse...]\" [...weitere Angaben...]&gt;<\/code>z.B.<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">&lt;a href=\"http:\/\/www.example.org\/\" target=\"_blank\"&gt;<\/code>Ein m\u00f6glicher Ausdruck daf\u00fcr ist recht schnell gefunden:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"wrong\" style=\"color: rgb(153, 0, 0); box-sizing: border-box;\">&lt;a href=\".*\".*&gt;<\/span><\/code>Sieht gut aus, klappt aber nicht. Warum?<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Der Autor hat sich zwar<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">gedacht<\/em><span>&nbsp;<\/span>der Ausdruck w\u00fcrde an der zu dem Link geh\u00f6renden schlie\u00dfenden Klammer aufh\u00f6ren, er tut es aber nicht. Im folgenden ein Ausschnitt aus einer HTML-Datei mit markiertem Treffer:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">&lt;BODY&gt; Bla Blubb 1 2 3<span>&nbsp;<\/span><span class=\"match\" style=\"box-sizing: border-box; background-color: rgb(0, 255, 0);\">&lt;a href=\"http:\/\/www.example.org\/\" target=\"_blank\"&gt; Linktext &lt;\/a&gt; Viel, viel weiterer &lt;i&gt;Text&lt;\/i&gt;<\/span><span>&nbsp;<\/span>Blubb 42<\/code>Das geht eindeutig zu weit! Der zweite Punkt ist zu &#8222;gierig&#8220; und frisst alle Zeichen sogar \u00fcber mehrere schlie\u00dfende spitze Klammern hinweg. In anderen Situationen w\u00e4re es denkbar, dass der erste Punkt \u00e4hnlich amokl\u00e4uft.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">F\u00fcr unseren Fall gibt es zwei L\u00f6sungsm\u00f6glichkeiten. Oft bleibt jedoch nur eine davon, daher stelle ich beide vor:<\/p>\n<ul style=\"color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; margin-top: 0px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">\n<li style=\"box-sizing: border-box;\"><span class=\"div\" style=\"box-sizing: border-box;\"><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">Den Punkt ersetzen<\/strong><span>&nbsp;<\/span>durch etwas was keine spitzen Klammern mehr frisst:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"wrong\" style=\"color: rgb(153, 0, 0); box-sizing: border-box;\">&lt;a href=\".*\"[^&gt;]*&gt;<\/span><\/code>Das ist eine oft anzuwendende Methode (\u00fcberlege dir, welche Zeichen das Ende markieren und schlie\u00dfe diese von dem zu treffenden aus). Das ganze muss jetzt nat\u00fcrlich noch analog f\u00fcr den ersten Punkt gemacht werden:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">&lt;a href=\"<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">[^\"]<\/span>*\"<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">[^&gt;]<\/span>*&gt;<\/code><\/span>\n<p style=\"margin: 0px 0px 14px; box-sizing: border-box;\"><\/p>\n<\/li>\n<li style=\"box-sizing: border-box;\"><span class=\"div\" style=\"box-sizing: border-box;\"><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">Den Punkt &#8222;umerziehen&#8220;<\/strong><span>&nbsp;<\/span>(bzw. * gen\u00fcgsam machen) so dass beide zusammen nur noch so viel fressen, wie unbedingt n\u00f6tig ist. Dies tut ein angeh\u00e4ngtes Fragezeichen, was dann nat\u00fcrlich nicht mehr die bisher bekannte Funktion hat:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">&lt;a href=\".*<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">?<\/span>\".*<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">?<\/span>&gt;<\/code>Nat\u00fcrlich funktioniert diese Sonderbenutzung des Fragezeichens auch hinter einem Pluszeichen.<\/span><\/li>\n<\/ul>\n<h3 id=\"Gruppen\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Gruppen<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">So gut wie alle RegEx-Dialekte erlauben das Bilden von Gruppen und deren Speicherung f\u00fcr sp\u00e4tere Verwendung. Auch dazu k\u00f6nnen Klammern dienen.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\"><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">Sp\u00e4tere Verwendung<\/strong><span>&nbsp;<\/span>kann z.B. hei\u00dfen, dass ein Ausdruck zwar auf eine l\u00e4ngere Zeichenkette treffen soll, aber nur ein Teil davon wirklich verwendet werden soll.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Soetwas w\u00e4re in Verbindung mit dem obigen Ausdruck sehr n\u00fctzlich, um alle Zieladressen aus einer HTML-Seite zu filtern.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Wie genau du an die Inhalte der Gruppen kommst, steht in der Anleitung der von dir verwendeten Sprache. Bei PHP findest du es z.B. bei<span>&nbsp;<\/span><a style=\"transition:color 0.2s; color: rgb(55, 90, 127); text-decoration: none; box-sizing: border-box; background-color: transparent;\" href=\"http:\/\/www.php.net\/preg_match\" target=\"_blank\">preg_match<\/a><span>&nbsp;<\/span>und Java soweit ich mich erinnern kann irgendwo in der N\u00e4he von regex.matcher. Google sollte da mehr zu wissen.<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">&lt;a href=\"<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">(<\/span>.*?<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">)<\/span>\".*?&gt;<\/code>Der erste Punkt und seine &#8222;Vervielfacher&#8220; sind eingeklammert. In der ersten Gruppe befindet sich jetzt also die URL.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Beachte, dass bei der Nummerierung der Gruppen die Reihenfolge der \u00f6ffnenden Klammer z\u00e4hlt. Das ist wichtig zu beachten bei verschachtelten Klammern. Au\u00dferdem z\u00e4hlen normalerweise<span>&nbsp;<\/span><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">alle Klammern<\/strong>, auch wenn sie nur zur Ausweisung von Alternativen (s.o.) verwendet werden.<\/p>\n<h3 id=\"Referenzen\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Referenzen<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Es gibt noch einen anderen, sehr n\u00fctzlichen Verwendungszweck f\u00fcr Gruppen. Stell dir vor, du willst in einer Folge von Zahlen (sagen wir sie seien mit einem Leerzeichen voneinander getrennt) all die Zahlen finden, die mit der selben Ziffer beginnen und enden.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Wir haben also<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">129 337873 78324 43938 9388 824998 349734<\/code>Dazu k\u00f6nnen wir solch einen Ausdruck verwenden:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">&nbsp;<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">(<\/span>[0-9]<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">)<\/span>[0-9]*<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">\\1<\/span><\/code>wobei das \\1 auf den Inhalt der<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">ersten Klammer<\/em><span>&nbsp;<\/span>verweist (referenziert) und daher an der Stelle von \\1 das selbe stehen muss wie in dieser Klammer. Das erste und letzte Zeichen<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">unseres Ausdrucks<\/em><span>&nbsp;<\/span>ist jeweils ein Leerzeichen, um damit das Ende und den Anfang einer Zahl zu kennzeichnen.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Schauen wir uns an, auf was er trifft:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">129<span class=\"match\" style=\"box-sizing: border-box; background-color: rgb(0, 255, 0);\"><span>&nbsp;<\/span>337873<span>&nbsp;<\/span><\/span>78324 43938 9388<span class=\"match\" style=\"box-sizing: border-box; background-color: rgb(0, 255, 0);\"><span>&nbsp;<\/span>824998<span>&nbsp;<\/span><\/span>349734<\/code>Wie du siehst, z\u00e4hlt das erste und letzte Leerzeichen auch immer noch zu dem jeweiligen Treffer dazu. Das ist auch kein Wunder, schlie\u00dflich steht vor und hinter unserem Ausdruck auch jeweils ein Leerzeichen. Das ist nicht wirklich gut, wenn uns dieses Leerzeichen eigentlich gar nicht interessiert. Daher stellt die RegEx-Sprache auch hier ein Mittel zur Verf\u00fcgung, welches auch funktioniert, wenn wir keine Gruppen benutzen m\u00f6chten oder k\u00f6nnen:<\/p>\n<h3 id=\"SpezielleZeichenWortgrenzen\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Spezielle Zeichen: Wortgrenzen<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Es gibt Zeichen, die stehen zwar im regul\u00e4ren Ausdruck, aber nicht in dem Text, der nachher gematcht wird. Das sagt dir jetzt nichts? Naja, schauen wir uns als ein Beispiel an, wie man obigen Ausdruck ohne die Leerzeichen schreibt:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">\\b<\/span>([0-9])[0-9]*\\1<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">\\b<\/span><\/code>Dieses &#8222;\\b&#8220; ist ein zusammengeh\u00f6riges Element und kennzeichnet ein Wortanfang oder ein Wortende (also eine Wortgrenze). Kennst du die in Textverarbeitungsprogrammen und Editoren oft verwendete M\u00f6glichkeit &#8222;Nur ganzes Wort suchen&#8220; in der Suchfunktion? W\u00e4hlst du diese aus, werden z.B. bei einer Suche nach &#8222;Kai&#8220; statt diesen Treffern<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"match\" style=\"box-sizing: border-box; background-color: rgb(0, 255, 0);\">Kai<\/span><span>&nbsp;<\/span>f\u00e4hrt nach<br style=\"box-sizing: border-box;\"><span class=\"match\" style=\"box-sizing: border-box; background-color: rgb(0, 255, 0);\">Kai<\/span>serslautern<\/code>nur noch dieser Treffer gefunden:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"match\" style=\"box-sizing: border-box; background-color: rgb(0, 255, 0);\">Kai<\/span><span>&nbsp;<\/span>f\u00e4hrt nach<br style=\"box-sizing: border-box;\">Kaiserslautern<\/code>Letzteres lie\u00dfe sich in regul\u00e4ren Ausdr\u00fccken so umsetzen bzw. ausdr\u00fccken:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">\\b<\/span>Kai<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">\\b<\/span><\/code>Also &#8222;Kai&#8220; nur, wenn es von Wortgrenzen umgeben ist. Was genau ist \u00fcberhaupt eine Wortgrenze? Eine Wortgrenze tritt zwischen einem Wort-Zeichen und einem Nichtwortzeichen auf. H\u00e4? (Erkl\u00e4rung folgt!)<\/p>\n<h3 id=\"SpezielleZeichenWeitereZeichen\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Spezielle Zeichen: Weitere Zeichen<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Es gibt &#8211; \u00dcberraschung! &#8211; noch mehr Sonderzeichen, die du verwenden kannst und die einen RegEx sch\u00f6n abk\u00fcrzen k\u00f6nnen. Diese bestehen immer aus einem Backslash gefolgt von einem weiteren Zeichen (Buchstaben). \u00dcbrigens steht ein gro\u00dfer Buchstabe dabei immer f\u00fcr das Gegenteil eines kleinen.<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">\\w&nbsp; \\W<\/code>Ein Wort-Zeichen (kleines w) steht genau f\u00fcr [a-zA-Z0-9] und ein Nichtwortzeichen (gro\u00dfes W) steht genau f\u00fcr alles andere, also [^a-zA-Z0-9].<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">\\d&nbsp; \\D<\/code>Ein Digit, also eine Ziffer von 0-9. Entspricht damit [0-9] und in der Gro\u00dfschreibung [^0-9].<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">\\b&nbsp; \\B<\/code>Die &#8222;kleine&#8220; Variante hast du ja oben schon kennengelernt. Ein gro\u00dfes B steht dementsprechend f\u00fcr alle Stellen, an denen keine Wortgrenze auftritt.<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">\\s&nbsp; \\S<\/code>Die Kleine Variante steht f\u00fcr alle Whitespaces: Das sind so gut wie alle Zeichen, die man nicht sieht. Also Return (bzw. Enter), Leertaste (Space), Tab(ulator).<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">\\\\<\/code>Wenn man mit Backslash, wie du gesehen hast, Sonderzeichen anf\u00e4ngt, muss man ja auch den Backslash selbst irgendwie fabrizieren k\u00f6nnen, wenn man genau diesen meint. Dies macht man einfach durch einen doppelten solchen. Man sagt: der erste &#8222;maskiert&#8220; den zweiten.<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">\\.&nbsp; \\+&nbsp; \\*&nbsp; \\(&nbsp; \\)&nbsp; \\[&nbsp; \\]&nbsp; \\-&nbsp; \\$&nbsp; \\|<\/code>Der Punkt und viele andere Zeichen haben, wie du oben gesehen hast, eine Sonderfunktion. Daher werden sie mittels eines Backslashs von dieser Sonderfunktion abgehalten (&#8222;maskiert&#8220;). Dies gilt f\u00fcr das Minuszeichen nur innerhalb von Zeichenklassen, daf\u00fcr darfst du in selbigen bei vielen anderen Zeichen die Backslashs weglassen.<\/p>\n<h3 id=\"AnfangsundEndezeichen\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Anfangs- und Endezeichen<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Stell dir vor, du willst ein Datum pr\u00fcfen, sagen wir mit<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">1\\.3\\.2004<\/code>Und diesen Ausdruck l\u00e4sst du auf<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">11.3.2004<\/code>los. Was kommt raus? Dein Ausdruck wird dir melden, dass er trifft. Ist ja auch irgendwo klar, schlie\u00dflich steht, wenn man eine Eins wegl\u00e4sst, dein Datum da. Du willst aber, dass das gesamte Datum wie deins aussieht? Gibt&#8217;s da nicht was von Ratiodingsbums? Doch gibts:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">^<\/span>1\\.3\\.2004<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">$<\/span><\/code>Dieses Dach am Anfang sagt: Treffe nur, wenn hier der zu durchsuchende String anf\u00e4ngt. Und das Dollarzeichen steht f\u00fcr: Treffe nur, wenn genau hier der zu durchsuchende String endet.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Selbstverst\u00e4ndlich kann man beide auch einzeln einsetzen; Als Beispiel schauen wir uns zwei regul\u00e4re Ausdr\u00fccke an: Der erste trifft auf einen String, der mit einer Zahl endet. Der zweite trifft auf einen String, der mit einer \u00f6ffnenden Klammer beginnt. Dabei benutzen wir die oben angegebene Maskierung f\u00fcr die Klammer.<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">\\d<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">$<\/span><br style=\"box-sizing: border-box;\"><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">^<\/span>\\(<\/code><\/p>\n<h3 id=\"PositiveLookaheadsundLookbehinds\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Positive Lookaheads und Lookbehinds<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Du hast jetzt M\u00f6glichkeiten kennengelernt, wie du Wortgrenzen feststellen kannst, ohne sie selbst wirklich mitzufressen. Es gibt auch eine universelle M\u00f6glichkeit.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Als Beispiel soll folgende Zahlenfolge dienen:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">000566403580000345050052301078906040092800100001007680<\/code>Aus dieser Zahlenfolge sollen alle jene Folgen herausgefischt werden, die drei Ziffern ungleich Null enthalten und von einer Null an jeder Seite begrenzt werden. In unserem Fall also &#8222;358&#8220;, &#8222;345&#8220;, &#8222;523&#8220;, &#8222;789&#8220;, &#8222;928&#8220; und &#8222;768&#8220;. Dazu kannst du folgenden Code benutzen:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">(?&lt;=0)<\/span>[1-9]{3}<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">(?=0)<\/span><\/code>Keine Panik! Zur Erkl\u00e4rung, und wir fangen in der Mitte an: das [1-9]{3} sollte klar sein (3 Ziffern ungleich Null). Davor findest du die Klammer (?&lt;=0). Die Zeichen ?&lt;= musst du &#8222;en bloc&#8220; betrachten und sie kennzeichnen eine Sonderfunktion f\u00fcr die Klammer. Diese steht damit f\u00fcr &#8222;vornedran eine Null&#8220;. Und weil &#8222;vornedran&#8220; in der normalen Leserichtung der westlichen Welt bedeutet, dass die Klammer &#8222;r\u00fcckw\u00e4rts&#8220; schaut, hei\u00dft diese Funktion &#8222;positive lookbehind&#8220;.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Genauso mit den Zeichen &#8222;?=&#8220;, diese weisen der Klammer die Sonderfunktion &#8222;hintendran muss &#8230; kommen&#8220; zu, in unserem Fall also &#8222;hintendran eine Null&#8220;. Das ganze nennt sich &#8222;positive lookahead&#8220;, weil die Klammer &#8222;nach vorne&#8220; schaut.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Unser &#8222;\\b&#8220;-Beispiel von oben k\u00f6nnten wir also auch folgenderma\u00dfen ausdr\u00fccken, wenn wir unser Wissen \u00fcber &#8222;\\W&#8220; benutzen:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">(?&lt;=\\W)<\/span>(\\d)\\d*\\1<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">(?=\\W)<\/span><\/code>Zur Erkl\u00e4rung fangen wir wieder in der Mitte an: Da steht der von oben bekannte Code (Eine Ziffer, beliebig viele weitere Ziffern und eine weitere Ziffer, die die gleiche wie die erste ist). Die allererste Klammer fordert vor der ersten Ziffer ein Nichtwortzeichen und die allerletzte Klammer ein Nichtwortzeichen hinter der letzten Ziffer.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Selbstverst\u00e4ndlich k\u00f6nnen lookaheads und lookbehinds auch einzeln in einem regul\u00e4ren Ausdruck vorkommen und sogar mehrfach. Das einzige, was<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">nicht<\/em><span>&nbsp;<\/span>geht, ist ein lookbehind mit einer unbekannten Anzahl von Zeichen. (also so Dingern wie *, + und {0,4})<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Alles klar? Wenn nicht, dann zur\u00fcck zum Anfang dieses Abschnitts, gehe nicht \u00fcber &#8222;Los&#8220; und ziehe keine 200 RegExen ein.<\/p>\n<h3 id=\"NegativeLookaheadsundLookbehinds\" style=\"color: rgb(68, 68, 68); text-transform: none; line-height: 1.1; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 24px; font-style: normal; font-weight: 600; margin-top: 28px; margin-bottom: 14px; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Negative Lookaheads und Lookbehinds<\/h3>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Du hast das kompliziert gefunden und siehst so langsam ein,<span>&nbsp;<\/span><strong style=\"font-weight: 500 !important; box-sizing: border-box;\">wie<\/strong><span>&nbsp;<\/span>voodoo regul\u00e4re Ausdr\u00fccke sind? Es kommt noch besser.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Dazu noch ein Beispiel: Du willst eine E-Mail-Adresse pr\u00fcfen, die aber nicht aus Frankreich stammen soll. Zun\u00e4chst schauen wir uns eine einfache E-Mail-Adressen-Pr\u00fcfung ohne die Einschr\u00e4nkung an:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[^@]+@.+\\.[^.]+<\/code>(Ein Zeichen ungleich dem @-Zeichen, gefolgt von einem @-Zeichen, beliebigen Zeichen (aber mindestens eins), einem Punkt und dahinter beliebige Zeichen, aber kein Punkt mehr. Trifft auf toll@example.com genau so wie auf viele_.Zeichen@noch.mehr.Punkte.example.com.) Wichtig: das letzte Paar von eckigen Klammern frisst immer den letzten Teil (die Top-Level-Domain, im Beispiel &#8222;com&#8220;) der E-Mail-Adresse.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Jetzt f\u00fcgen wir eine Beschr\u00e4nkung ein und wollen &#8222;fr&#8220; an dieser Stelle ausschlie\u00dfen. Auf den Punkt darf also nicht &#8222;fr&#8220; folgen.<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">[^@]+@.+\\.<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">(?!fr)<\/span>[^.]+<\/code>erledigt das f\u00fcr uns. ?! kennzeichnet eine Klammer also als &#8222;hier darf<span>&nbsp;<\/span><em style=\"box-sizing: border-box;\">nicht<\/em><span>&nbsp;<\/span>folgen&#8220;.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Damit k\u00f6nnte man auch eine besondere Suche nach einem Wort gestalten.<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">\\bF<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">(?!<\/span>eta\\b<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">)<\/span>.*\\b<\/code>trifft auf alle W\u00f6rter, die mit &#8222;F&#8220; anfangen, aber ungleich &#8222;Feta&#8220; sind. Im folgenden Text sind alle Strings markiert, die getroffen werden:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\"><span class=\"match\" style=\"box-sizing: border-box; background-color: rgb(0, 255, 0);\">Fett<\/span><span>&nbsp;<\/span>Feta<span>&nbsp;<\/span><span class=\"match\" style=\"box-sizing: border-box; background-color: rgb(0, 255, 0);\">Falsch<\/span><span>&nbsp;<\/span><span class=\"match\" style=\"box-sizing: border-box; background-color: rgb(0, 255, 0);\">Feucht<\/span><span>&nbsp;<\/span><span class=\"match\" style=\"box-sizing: border-box; background-color: rgb(0, 255, 0);\">Fuffziger<\/span><\/code>Das war der &#8222;negative lookahead&#8220;.<\/p>\n<p style=\"margin: 0px 0px 14px; color: rgb(68, 68, 68); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: roboto, &quot;Helvetica Neue&quot;, helvetica, sans-serif; font-size: 18px; font-style: normal; font-weight: 300; word-spacing: 0px; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\">Und weils so sch\u00f6n war, leg ich noch einen drauf, den &#8222;negative lookbehind&#8220;:<code class=\"block\" style=\"padding: 2px 4px; border-radius: 4px; color: rgb(0, 102, 102); font-family: consolas, &quot;Liberation Mono&quot;, courier, monospace; font-size: 16.2px; margin-top: 0.25em; margin-bottom: 0.25em; margin-left: 1em; display: block; box-sizing: border-box; background-color: rgb(224, 224, 224);\">.*<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">(?&lt;!<\/span>M\u00fcll<span class=\"new\" style=\"box-sizing: border-box; background-color: rgb(255, 255, 0);\">)<\/span>eimer<\/code>trifft auf alle Eimer, in die kein M\u00fcll geh\u00f6rt, meint also: &#8222;treffe an dieser Stelle, wenn davor kein &#8222;M\u00fcll&#8220; steht&#8220;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Da gibt es eine wirklich nette Seite, wo das Thema kurz und knackig erl\u00e4utert wird. Sollte man als Anf\u00e4nger mal<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1058","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"https:\/\/abchaus.synology.me\/wordpress\/wp-json\/wp\/v2\/posts\/1058","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/abchaus.synology.me\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/abchaus.synology.me\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/abchaus.synology.me\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/abchaus.synology.me\/wordpress\/wp-json\/wp\/v2\/comments?post=1058"}],"version-history":[{"count":1,"href":"https:\/\/abchaus.synology.me\/wordpress\/wp-json\/wp\/v2\/posts\/1058\/revisions"}],"predecessor-version":[{"id":1059,"href":"https:\/\/abchaus.synology.me\/wordpress\/wp-json\/wp\/v2\/posts\/1058\/revisions\/1059"}],"wp:attachment":[{"href":"https:\/\/abchaus.synology.me\/wordpress\/wp-json\/wp\/v2\/media?parent=1058"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/abchaus.synology.me\/wordpress\/wp-json\/wp\/v2\/categories?post=1058"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/abchaus.synology.me\/wordpress\/wp-json\/wp\/v2\/tags?post=1058"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}