Regular expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prabunewindia
    New Member
    • Mar 2007
    • 199

    Regular expression

    Hi,

    I want to take the particular words from a text document.
    i.e., Need to take all the sentence starts with "Alter" and End with "null"
    Can any one help me to do this....

    Rajendra Prabu Elias
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    What have you done so far?
    Hint: You may get away by just using the methods in the string class for this.

    Comment

    • prabunewindia
      New Member
      • Mar 2007
      • 199

      #3
      Originally posted by r035198x
      What have you done so far?
      Hint: You may get away by just using the methods in the string class for this.
      thanks for reply

      I want to do it thru regular expression.
      I tried the below

      Code:
      txtOutput.Text="";         
      Regex exp = new Regex("ALTER[\\D]*NULL", RegexOptions.Multiline);         
      MatchCollection mcol= exp.Matches(txtInput.Text);         
      foreach (Match mat in mcol)         
      {
                   txtOutput.Text = txtOutput.Text+ "\n" + mat.Value.ToString();         
      }
      I dont know what to give for {allow any character}. thats why I tried with [\\D].

      If I have more line like "Alter ..... NULL" then it should display all the lines.
      Now it is display getting "alter .... null .... alter.... null" into a single sentence.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Why do you want to do it in regex when simple StartsWith and EndsWith methods will do the job?

        Comment

        • prabunewindia
          New Member
          • Mar 2007
          • 199

          #5
          Originally posted by r035198x
          Why do you want to do it in regex when simple StartsWith and EndsWith methods will do the job?
          Thaks for reply

          I will tell you my exact meed.

          I will have a text document (SQL script).

          I want to find particular sentence Starts with "ALTER" and end with "NULL"

          It may occur in many times. So I need to list all the lines. With my above method, it displayed first a single setance by considering first ALTER and last NULL. But I i.e., It displayed all the sentence from first ALTER and before last NULL.

          Regards,
          Rajendra Prabu

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            You can use .* to match any characters.

            Comment

            Working...