September 30th, 2010, 07:58 AM
-
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!
September 30th, 2010, 08:14 AM
-
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.
September 30th, 2010, 08:20 AM
-
September 30th, 2010, 02:01 PM
-
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.