Click here to Skip to main content
14,771,107 members
Home » Discussions » Regular Expressions
   

Regular Expressions

 
GeneralRe: Help with regex HTML form validation Pin
robwm110-Oct-14 8:39
Memberrobwm110-Oct-14 8:39 
GeneralRe: Help with regex HTML form validation Pin
Richard Deeming10-Oct-14 8:47
mveRichard Deeming10-Oct-14 8:47 
QuestionRegular expression date Pin
Member 836446830-May-14 8:27
MemberMember 836446830-May-14 8:27 
QuestionRe: Regular expression date Pin
George Jonsson14-Sep-14 0:21
professionalGeorge Jonsson14-Sep-14 0:21 
AnswerRe: Regular expression date Pin
nagshead_obx9-Oct-14 8:10
Membernagshead_obx9-Oct-14 8:10 
QuestionRe: Regular expression date Pin
George Jonsson9-Oct-14 17:18
professionalGeorge Jonsson9-Oct-14 17:18 
QuestionRegex to extact lines of code know the start and ending Pin
susanab17-Apr-14 4:25
Membersusanab17-Apr-14 4:25 
QuestionRe: Regex to extact lines of code know the start and ending Pin
Matt T Heffron17-Apr-14 9:14
professionalMatt T Heffron17-Apr-14 9: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.
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:
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 5:10
professionalMarco Bertschi20-Mar-14 5:10 
AnswerMessage Closed Pin
20-Mar-14 5:44
professionalPeter Leow20-Mar-14 5:44 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 6:24
professionalMarco Bertschi20-Mar-14 6:24 
GeneralRe: A little help needed... Pin
Haloniels19977-Sep-14 12:36
MemberHaloniels19977-Sep-14 12:36 
QuestionRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 5:55
professionalKornfeld Eliyahu Peter20-Mar-14 5:55 
AnswerRe: A little help needed... Pin
Marco Bertschi20-Mar-14 6:21
professionalMarco Bertschi20-Mar-14 6:21 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 6:37
professionalKornfeld Eliyahu Peter20-Mar-14 6:37 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 6:49
professionalMarco Bertschi20-Mar-14 6:49 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 7:27
professionalKornfeld Eliyahu Peter20-Mar-14 7:27 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 11:17
professionalMarco Bertschi20-Mar-14 11:17 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 11:58
professionalKornfeld Eliyahu Peter20-Mar-14 11:58 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 12:21
professionalMarco Bertschi20-Mar-14 12:21 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 12:28
professionalKornfeld Eliyahu Peter20-Mar-14 12:28 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 12:59
professionalMarco Bertschi20-Mar-14 12:59 
GeneralRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 13:08
professionalKornfeld Eliyahu Peter20-Mar-14 13:08 
GeneralRe: A little help needed... Pin
Marco Bertschi20-Mar-14 13:14
professionalMarco Bertschi20-Mar-14 13:14 
JokeRe: A little help needed... Pin
Kornfeld Eliyahu Peter20-Mar-14 13:17
professionalKornfeld Eliyahu Peter20-Mar-14 13:17 

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.