Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Problem mit regulären Ausdrücken (mal wieder)

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

ich hab ein Problem mit regulären Ausdrücken. Aufgabe: Ich möchte alle Satzbestandteile aus einem String rausklammüsern.

Beispielstring:

Trallala <sup>Test</sup> ist cool <sub>Sub</sub> eigentlich auch. Und <sup>Das</sup> eigentlich auch.

Ich bräuchte einen regulären Ausdruck, der mir folgende bestandteile liefert:

Trallala

<sup>Test</sup>

ist cool

<sub>Sub</sub>

eigentlich auch. Und

<sup>Das</sup>

eigentlich auch.

Weiss da einer Rat.

Danke schon mal

welche Sprache?

Hoppla, hatte ich vergessen. PHP sollte es sein

Ich probier mich mal:


$pattern = "|(.+?[(<sup>.+?</sup>)|(<sub>.+?</sub>)].+?)*|";
if (preg_match_all ( $pattern, $subject, $matches ) != false ) { // keine Beachtung der Typen, 0 und false erfüllen die Bedingung
// Ergebnisse stehen in $matches drin
// Sortierung kann mit weiteren Flags gesteuert werden
// siehe: http://de.php.net/manual/en/function.preg-match-all.php
}
else {
// no matches
}
[/PHP]

Danke für den Tipp, hab das jetzt wie folgt gelöst:

$a=preg_split('/(<[^>]+>[^<]+<\/[^>]+>)/i', $html, -1, PREG_SPLIT_DELIM_CAPTURE);

Das funktioniert prima

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.