#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Find Start and Finish of Section


    I have a bunch of text and I am wanting to find the start and end of the text as well as everything between.

    Basically the text starts with either "case" or "story" and then will have anything after that including various punctuation, end lines, characters, etc. It will then end with either the word "end" or "tbc".

    Example:
    story starts here and
    will keep going, and going. At some point
    anywhere it will be done.
    the end
    case will sometimes follow or another
    of the first option will contine
    tbc


    I can do this (case|story).* but it just gets the first line. I cant figure out how to get the whole thing. Basically I want to see two groupings of one with the story and the other with the case.

    I am new at regex. HELP!
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Generally, it's good to tell us what language you're trying to use the regex in. A PHP solution:
    PHP Code:
    $stories 'story starts here and
    will keep going, and going. At some point
    anywhere it will be done.
    the end
    case will sometimes follow or another
    of the first option will contine
    tbc'
    ;

    preg_match_all("/(story|case).+?(end|tbc)$/ims"$stories$foo);

    echo 
    "Story 1: {$foo[0][0]}\n\n\nStory 2: {$foo[0][1]}";
    //etc, all matched stories will be in the array $foo[0] 
    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0
    Sorry! Language is C#.
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    The epxression should still work, though you'd have to figure out how to do "flags" in C#. The "ims" at the end of my expression is critical.

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo