Gegeben die Zeichenfolge foobarbarbarfoobar, möchte ich alles zwischen foo haben. Also habe ich diesen Ausdruck dafür benutzt und das Ergebnis ist: barbarbar. Es funktioniert großartig.Regulärer Ausdruck, stimmen Sie alles nicht in
(?<=foo).*(?=foo)
Jetzt möchte ich auch das Gegenteil. Also, wenn ich die Zeichenfolge foobarbarbarfoobar habe, möchte ich alles, was nicht von foo eingeschlossen ist. Ich habe versucht, den folgenden regulären Ausdruck:
(?<!foo).*(?!foo)
I bar als Ergebnis erwartet, aber stattdessen gibt es eine Übereinstimmung für foobarbarbarfoobar. Es ergibt keinen Sinn für mich. Was vermisse ich?
Die Erklärung von: https://regex101.com/ sieht gut aus für mich?
(?<!foo).*(?!foo)
(?<!foo) Negative Lookbehind - Assert that it is impossible to match the regex below
foo matches the characters foo literally (case sensitive)
.* matches any character (except newline)
Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
(?!foo) Negative Lookahead - Assert that it is impossible to match the regex below
foo matches the characters foo literally (case sensitive)
Jede Hilfe ist wirklich