Click here to Skip to main content
15,881,588 members
Home / Discussions / Regular Expressions
   

Regular Expressions

 
GeneralRe: Help with regex HTML form validation Pin
robwm110-Oct-14 7:39
robwm110-Oct-14 7:39 
GeneralRe: Help with regex HTML form validation Pin
Richard Deeming10-Oct-14 7:47
mveRichard Deeming10-Oct-14 7:47 
QuestionRegular expression date Pin
Member 836446830-May-14 7:27
Member 836446830-May-14 7:27 
QuestionRe: Regular expression date Pin
George Jonsson13-Sep-14 23:21
professionalGeorge Jonsson13-Sep-14 23:21 
AnswerRe: Regular expression date Pin
nagshead_obx9-Oct-14 7:10
nagshead_obx9-Oct-14 7:10 
QuestionRe: Regular expression date Pin
George Jonsson9-Oct-14 16:18
professionalGeorge Jonsson9-Oct-14 16:18 
QuestionRegex to extact lines of code know the start and ending Pin
susanab17-Apr-14 3:25
susanab17-Apr-14 3:25 
QuestionRe: Regex to extact lines of code know the start and ending Pin
Matt T Heffron17-Apr-14 8:14
professionalMatt T Heffron17-Apr-14 8:14 
It isn't clear what the form of your input to the Regex is.
What you show as "Line" is actually 4 lines (ignoring the blank lines).
So is all of this really in a single string?
I.e.
C#
string Line = "Ques xx dd\nStack #1:\nTask id #330\nTaskRecord{ccsssew fs sfsdf sdfsdf}";

Or are the lines separate strings in an array or list, or are they being read in line-at-a-time?

In any case, the Regex you have is not correct.
The } needs to be before the end of the line!
For the ^ and $ to match beginning and end of line (not beginning and end of the whole string) you need to use Multiline mode.
But to have . also match the \n (end of line) you need to use Singleline mode.
I suppose having both modes set can work (I haven't tried it), but it will sure look strange in the code!!!

So, if your input is separate strings that you are "processing" sequentially, you should do something like:
C#
bool collecting = false;
List<string> collected = new List<string>();
foreach (string line in source-of-text-line-by-line)
{
  if (!collecting && line.StartsWith("Stack"))
  {
    collecting = true;
    collected.Clear();
  }
  if (collecting)
  {
    collected.Add(line);
    if (line.EndsWith("}"))
    {
      collecting = false;
      // Here do whatever processing you want with this set of collected lines
    }
  }
}

Question[Solved] Pin
Marco Bertschi20-Mar-14 4:10
protectorMarco Bertschi20-Mar-14 4:10 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 5:24
protectorMarco Bertschi20-Mar-14 5:24 
GeneralRe: A little help needed... Pin
Haloniels19977-Sep-14 11:36
Haloniels19977-Sep-14 11:36 
QuestionRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 4:55
professionalKornfeld Eliyahu Peter20-Mar-14 4:55 
AnswerRe: A little help needed... Pin
Marco Bertschi20-Mar-14 5:21
protectorMarco Bertschi20-Mar-14 5:21 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 5:37
professionalKornfeld Eliyahu Peter20-Mar-14 5:37 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 5:49
protectorMarco Bertschi20-Mar-14 5:49 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 6:27
professionalKornfeld Eliyahu Peter20-Mar-14 6:27 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 10:17
protectorMarco Bertschi20-Mar-14 10:17 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 10:58
professionalKornfeld Eliyahu Peter20-Mar-14 10:58 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 11:21
protectorMarco Bertschi20-Mar-14 11:21 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 11:28
professionalKornfeld Eliyahu Peter20-Mar-14 11:28 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 11:59
protectorMarco Bertschi20-Mar-14 11:59 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 12:08
professionalKornfeld Eliyahu Peter20-Mar-14 12:08 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 12:14
protectorMarco Bertschi20-Mar-14 12:14 
JokeRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 12:17
professionalKornfeld Eliyahu Peter20-Mar-14 12:17 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 20:23
protectorMarco Bertschi20-Mar-14 20:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.