Reguläre Ausdrücke der Befehl \b
-
- User
- Beiträge: 43
- Registriert: Montag 18. April 2022, 13:13
Es geht um den Befehl \b bei python und zwar versthe ich nicht ganz was es genau macht
-
- User
- Beiträge: 43
- Registriert: Montag 18. April 2022, 13:13
der ausdruck r".*?\b(\w+)\s+\1\b.*" was genau macht das b ?
Zuletzt geändert von MathGenie123 am Montag 11. Juli 2022, 10:16, insgesamt 1-mal geändert.
Wenn es nur einen Platz gaebe, an dem man sowas nachschlagen kann.
Oh warte. Gibt es: https://docs.python.org/3/library/re.ht ... ion-syntax
Du musst dir echt ein bisschen mehr Muehe geben.
Oh warte. Gibt es: https://docs.python.org/3/library/re.ht ... ion-syntax
Du musst dir echt ein bisschen mehr Muehe geben.
-
- User
- Beiträge: 43
- Registriert: Montag 18. April 2022, 13:13
und das genau verstehe ich nicht so ganz
Matches the empty string, but only at the beginning or end of a word. A word is defined as a sequence of word characters. Note that formally, \b is defined as the boundary between a \w and a \W character (or vice versa), or between \w and the beginning/end of the string. This means that r'\bfoo\b' matches 'foo', 'foo.', '(foo)', 'bar foo baz' but not 'foobar' or 'foo3'.
Matches the empty string, but only at the beginning or end of a word. A word is defined as a sequence of word characters. Note that formally, \b is defined as the boundary between a \w and a \W character (or vice versa), or between \w and the beginning/end of the string. This means that r'\bfoo\b' matches 'foo', 'foo.', '(foo)', 'bar foo baz' but not 'foobar' or 'foo3'.
-
- User
- Beiträge: 43
- Registriert: Montag 18. April 2022, 13:13
Ah das /b steht dafür dass alles Zeichen gematch werden bei foo die das komplement von /w sind ? also zeichen wie /., etc etc ? dabei können diese zeichen am anfang oder am ende oder sonst wo stehen ?
Auf dieser Seite kannst du hemmungslos mit Regex rumspielen und die Bedeutungen ausprobieren.
https://regexr.com/
https://regexr.com/
Ich bin Pazifist und greife niemanden an, auch nicht mit Worten.
Für alle meine Code Beispiele gilt: "There is always a better way."
https://projecteuler.net/profile/Brotherluii.png
Für alle meine Code Beispiele gilt: "There is always a better way."
https://projecteuler.net/profile/Brotherluii.png
- noisefloor
- User
- Beiträge: 4196
- Registriert: Mittwoch 17. Oktober 2007, 21:40
- Wohnort: WW
- Kontaktdaten:
...oder https://regex101.com/ , welche mehr Programmiersrpachen unterstützt (inkl. Python). Und die Erklärung der RegEx anders aufteilt als regexr.com. Ist aber letztendlich Geschmackssache, was einem besser gefällt / man besser versteht.
Gruß, noisefloor
Gruß, noisefloor