Ankündigung

Einklappen
Keine Ankündigung bisher.

Regex - nur Wörte nach bestimmten Regeln

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Regex - nur Wörte nach bestimmten Regeln

    Hallo Leute, ich habe hier eine kleine Herausforderung für Euch....

    Ich komme leider nicht weiter.

    Ich möchte aus einem Text alle Worter fischen die...

    Mit einem Großbuchtstaben beginnen
    Nicht am Satzanfang stehen
    Wörter mit bindestrich werden als ein Wort gesehen.

    Mein Regex:
    (?<![.!?]) \b([A-ZÄÖÜ\-][\wäöüß\-]*)



    Mein Testtext:

    alle groß beginnen.
    nicht am satzanfang
    bindestriche ok (als ein wort)


    Malmö FF are a Swedish professional football club based in Malmö. The club play their home matches at Swedbank Stadion. Formed on 24 February 1910, the club have won sixteen national championship titles and fourteen national cup titles, making them the most successful club in Sweden in terms of total trophies won. Malmö FF have also won the top tier league, Allsvenskan, on three occasions when the title of Swedish champions was not decided by the outcome of that league. They were the runners-up in the 1978–79 European Cup final, which they lost 1–0 to English club Nottingham Forest. This feat makes them the only Scandinavian club to have made it to the final of the most prestigious club competition in European football, presently named the UEFA Champions League. The club are currently playing in Allsvenskan, where the season lasts from April to October in contrast to a majority of other European national football leagues where the season lasts from August to May the following year. The club first won Allsvenskan in 1944 and most recently for the club's centennial anniversary in 2010. timo-treue timo-treue
    Angehängte Dateien

  • #2
    Zitat von Fragensteller Beitrag anzeigen
    ...
    Ich möchte aus einem Text alle Worter fischen die...

    Mit einem Großbuchtstaben beginnen
    Nicht am Satzanfang stehen
    Wörter mit bindestrich werden als ein Wort gesehen.

    Mein Regex:
    (?<![.!?]) \b([A-ZÄÖÜ\-][\wäöüß\-]*)
    ...
    PHP-Code:
    $pcre '/
        (?<!\p{P}\s) # (vorheriges) Satzende: punctuation mark + whitespace
        \p{Lu}\p{M}* # Groszbuchstabe
        (?:\p{L}\p{M}*|-)* # weitere folgende beliebige Buchstaben + "Bindestrich"
    /ux'
    ;

    $haystack '...' // Dein Beispieltext

    preg_match_all($pcre$haystack$h); 
    Ein Dump von $h sieht für deinen Beispieltext so aus:
    Code:
    array(1) {
      [0] => array(27) {
        [0] => string(6) "Malmö"
        [1] => string(2) "FF"
        [2] => string(7) "Swedish"
        [3] => string(6) "Malmö"
        [4] => string(8) "Swedbank"
        [5] => string(7) "Stadion"
        [6] => string(8) "February"
        [7] => string(6) "Sweden"
        [8] => string(2) "FF"
        [9] => string(7) "Swedish"
        [10] => string(8) "European"
        [11] => string(3) "Cup"
        [12] => string(7) "English"
        [13] => string(10) "Nottingham"
        [14] => string(6) "Forest"
        [15] => string(12) "Scandinavian"
        [16] => string(8) "European"
        [17] => string(4) "UEFA"
        [18] => string(9) "Champions"
        [19] => string(6) "League"
        [20] => string(11) "Allsvenskan"
        [21] => string(5) "April"
        [22] => string(7) "October"
        [23] => string(8) "European"
        [24] => string(6) "August"
        [25] => string(3) "May"
        [26] => string(11) "Allsvenskan"
      }
    }

    Kommentar


    • #3
      Upps. Korrektur:

      PHP-Code:
      $pcre '/
          (?<!\A) # Textanfang ist auch ein Satzanfang
          (?<![?!.]\s) # (vorheriges) Satzende: ?!. + whitespace
          (?<=\P{L}) # Wortanfang (kein vorheriger Buchstabe)
          \p{Lu}\p{M}* # Groszbuchstabe
          (?:\p{L}\p{M}*|-)* # weitere folgende beliebige Buchstaben + "Bindestrich"
      /ux'

      Die Ausgabe ändert sich entsprechend.

      Wieso kann man hier eigene Posts nicht editieren?

      Kommentar

      Lädt...
      X