Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. Splitting with optionally second line

Splitting with optionally second line

Scheduled Pinned Locked Moved Regular Expressions
regexhelpquestion
3 Posts 2 Posters 11 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    G Team23
    wrote on last edited by
    #1

    Hi, I want to split the text above in three results. Every result starts with the word "Leistung" and can optionally have a second line starting with "Zusatz". My regex-expression ist currently this:

    /Leistung [ ]*[\w\d äöüÄÖÜ]*\n[\w\d äöüÄÖÜ\*]*/gm

    But this does not fit exactly. This ist the text:

    Leistung Armeotraining ET Anzahl 1
    Zusatz *TextZusatz_Anf1*
    Leistung Atemtherapie 30 Anzahl 2
    Leistung Aktivierungsgruppe Anzahl 3
    Zusatz *TextZusatz_Anf3*

    The result should be:

    Leistung Armeotraining ET Anzahl 1
    Zusatz *TextZusatz_Anf1*

    Leistung Atemtherapie 30 Anzahl 2

    Leistung Aktivierungsgruppe Anzahl 3
    Zusatz *TextZusatz_Anf3*

    Can anyone help me with the regex-expression? Thank you in advance! Tobias

    Richard DeemingR 1 Reply Last reply
    0
    • G G Team23

      Hi, I want to split the text above in three results. Every result starts with the word "Leistung" and can optionally have a second line starting with "Zusatz". My regex-expression ist currently this:

      /Leistung [ ]*[\w\d äöüÄÖÜ]*\n[\w\d äöüÄÖÜ\*]*/gm

      But this does not fit exactly. This ist the text:

      Leistung Armeotraining ET Anzahl 1
      Zusatz *TextZusatz_Anf1*
      Leistung Atemtherapie 30 Anzahl 2
      Leistung Aktivierungsgruppe Anzahl 3
      Zusatz *TextZusatz_Anf3*

      The result should be:

      Leistung Armeotraining ET Anzahl 1
      Zusatz *TextZusatz_Anf1*

      Leistung Atemtherapie 30 Anzahl 2

      Leistung Aktivierungsgruppe Anzahl 3
      Zusatz *TextZusatz_Anf3*

      Can anyone help me with the regex-expression? Thank you in advance! Tobias

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      It will depend on the "flavour" of regex you're using, but something like this seems to work for me:

      ^Leistung.*$(\n^Zusatz.*$)?

      Demo[^] Make sure your regex has the "global" and "multi-line" options set, so that $ matches the end of a line rather than the end of the input string.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      G 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        It will depend on the "flavour" of regex you're using, but something like this seems to work for me:

        ^Leistung.*$(\n^Zusatz.*$)?

        Demo[^] Make sure your regex has the "global" and "multi-line" options set, so that $ matches the end of a line rather than the end of the input string.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        G Offline
        G Offline
        G Team23
        wrote on last edited by
        #3

        Thank you, that worked for me!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups