need a reg expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AAaron123

    need a reg expression

    I want to search my .vb files for lines that do not contain an underline
    followed by Menu.

    I tried [!_].*Menu as a regular expression but I guess that must mean that
    it must contain a character that is not an _ followed by Menu.

    Is that correct?

    what would work?

    thanks


  • jamil@onepost.net

    #2
    Re: need a reg expression

    On Wed, 9 Apr 2008 07:38:24 -0400, "AAaron123"
    <aaaron123@road runner.comwrote :
    >Thanks that's good to know.
    >
    >I'm thinking now that
    >[!_].*Menu
    >means to find a character other than _ followed by Menu.
    >
    >I need to find a line that has no _ at all, followed by Menu.
    >
    >Thanks again
    If you mean the _ character immediately followed by Menu (no spacing),
    try this:

    (?<!_)(?:Menu|)

    Test subjects:

    123 _Menu 566
    123 Menu 456
    123 456
    123_ Menu 456

    Lines two and four match. The rest do not.

    If you mean the _ character followed by Menu (including spacing), try
    this:

    (?<!_\s*)(?:Men u|)

    Line two matches the test subjects. The rest do not.

    Comment

    • jamil@onepost.net

      #3
      Re: need a reg expression

      On Thu, 10 Apr 2008 06:33:25 -0400, jamil@onepost.n et wrote:
      >If you mean the _ character immediately followed by Menu (no spacing),
      >try this:
      >
      >(?<!_)(?:Menu| )
      You can simplify this and get the same result by removing the last
      group:

      (?<!_)Menu

      I created this quickly this morning and forgot to remove it.
      >If you mean the _ character followed by Menu (including spacing), try
      >this:
      >
      >(?<!_\s*)(?:Me nu|)
      Same for this one:

      (?<!_\s*)Menu

      Comment

      • AAaron123

        #4
        Re: need a reg expression

        What I meant is that the word Menu should appear and that there should not
        be an underscore any place before it.

        Are you using ! for negation? Shouldn't it be ^ (see Tom Shelton's earlier
        reply.)

        Thanks a lot


        <jamil@onepost. netwrote in message
        news:dc5tv3l92o etsqmdb4mvemlqp hv27n26q1@4ax.c om...
        On Thu, 10 Apr 2008 06:33:25 -0400, jamil@onepost.n et wrote:
        >
        >>If you mean the _ character immediately followed by Menu (no spacing),
        >>try this:
        >>
        >>(?<!_)(?:Menu |)
        >
        You can simplify this and get the same result by removing the last
        group:
        >
        (?<!_)Menu
        >
        I created this quickly this morning and forgot to remove it.
        >
        >>If you mean the _ character followed by Menu (including spacing), try
        >>this:
        >>
        >>(?<!_\s*)(?:M enu|)
        >
        Same for this one:
        >
        (?<!_\s*)Menu

        Comment

        • jamil@onepost.net

          #5
          Re: need a reg expression

          On Fri, 11 Apr 2008 15:16:11 -0400, "AAaron123"
          <aaaron123@road runner.comwrote :
          >What I meant is that the word Menu should appear and that there should not
          >be an underscore any place before it.
          Then try this:

          (?<!_.*)Menu
          >Are you using ! for negation? Shouldn't it be ^ (see Tom Shelton's earlier
          >reply.)
          >
          >Thanks a lot
          The earlier reply doesn't do what you are asking for.

          Comment

          • jamil@onepost.net

            #6
            Re: need a reg expression

            On Fri, 11 Apr 2008 15:16:11 -0400, "AAaron123"
            <aaaron123@road runner.comwrote :
            >What I meant is that the word Menu should appear and that there should not
            >be an underscore any place before it.
            Then try this:

            (?<!_.*)Menu
            >Are you using ! for negation? Shouldn't it be ^ (see Tom Shelton's earlier
            >reply.)
            >
            >Thanks a lot
            The earlier reply doesn't do what you are asking for.

            Comment

            • AAaron123

              #7
              Re: need a reg expression

              That works.

              Are Regular expressions rules the same in, say, Unix, Perl and Windows?


              Thanks

              And I found out about [^aeiou] and (?<! ) so thanks to Tom Shelton also


              <jamil@onepost. netwrote in message
              news:je00049nor blelu4mvsmj9brm s6nuurge0@4ax.c om...
              On Fri, 11 Apr 2008 15:16:11 -0400, "AAaron123"
              <aaaron123@road runner.comwrote :
              >
              >>What I meant is that the word Menu should appear and that there should not
              >>be an underscore any place before it.
              >
              Then try this:
              >
              (?<!_.*)Menu
              >
              >>Are you using ! for negation? Shouldn't it be ^ (see Tom Shelton's
              >>earlier
              >>reply.)
              >>
              >>Thanks a lot
              >
              The earlier reply doesn't do what you are asking for.

              Comment

              • AAaron123

                #8
                Re: need a reg expression

                I'm using Regex.Match and (?<!_.*)Menu works OK if there is just one line
                but if I give it the following string it does not match the second line.

                fhgfghfh_dfdfg

                sdfsdfsdfMenu

                sdfsdfsdf

                Do I have to call it one line at a time?



                Thanks again



                I tried with out success: with and without RegexOptions.Mu ltiline.

                Also tried with out success: ^(?<!_.*)Menu

                Not really sure what these constructs mean, just trying things.








                <jamil@onepost. netwrote in message
                news:je00049nor blelu4mvsmj9brm s6nuurge0@4ax.c om...
                On Fri, 11 Apr 2008 15:16:11 -0400, "AAaron123"
                <aaaron123@road runner.comwrote :
                >
                >>What I meant is that the word Menu should appear and that there should not
                >>be an underscore any place before it.
                >
                Then try this:
                >
                (?<!_.*)Menu
                >
                >>Are you using ! for negation? Shouldn't it be ^ (see Tom Shelton's
                >>earlier
                >>reply.)
                >>
                >>Thanks a lot
                >
                The earlier reply doesn't do what you are asking for.

                Comment

                • jamil@onepost.net

                  #9
                  Re: need a reg expression

                  On Sat, 12 Apr 2008 03:33:34 -0400, "AAaron123"
                  <aaaron123@road runner.comwrote :
                  >That works.
                  >
                  >Are Regular expressions rules the same in, say, Unix, Perl and Windows?
                  >
                  >
                  >Thanks
                  Different regular expressions engines exhibit different behavior and
                  features. They all share similarities though.

                  The engine in .NET is quite powerful and full-featured.

                  Comment

                  • jamil@onepost.net

                    #10
                    Re: need a reg expression

                    On Sat, 12 Apr 2008 04:02:29 -0400, "AAaron123"
                    <aaaron123@road runner.comwrote :
                    >I'm using Regex.Match and (?<!_.*)Menu works OK if there is just one line
                    >but if I give it the following string it does not match the second line.
                    >
                    >fhgfghfh_dfd fg
                    >
                    >sdfsdfsdfMen u
                    >
                    >sdfsdfsdf
                    >
                    >Do I have to call it one line at a time?
                    I just threw together some quick code that works fine:

                    Dim oRegex As Regex
                    Dim oMatch As Match
                    Dim strTest As String

                    strTest = "fhgfghfh_dfdfg " & vbCrLf & "sdfsdfsdfM enu" & vbCrLf &
                    "sdfsdfsdf"

                    oRegex = New Regex("(?<!_.*) Menu")
                    oMatch = oRegex.Match(st rTest)

                    While oMatch.Success
                    Call MsgBox("Matched at position: " & oMatch.Index,
                    MsgBoxStyle.Inf ormation)
                    oMatch = oMatch.NextMatc h
                    End While

                    Call MsgBox("No more matches found.", MsgBoxStyle.Inf ormation)

                    Comment

                    • AAaron123

                      #11
                      Re: need a reg expression

                      Thanks for all the help.
                      Besides what you showed me my underlying problem was the string contained
                      CR(13) for line endings.
                      I checked a RichTextBox.Tex t and it contained LF for line endings.
                      I expected CRLF since I thought the was the way of Windows.

                      Any way I replace CR wit LF and replace works OK now.

                      Must be Regex looks for LF.
                      Sound right to you?

                      I'd like my code to act the same as
                      VS2008/Edit/Find In Files/Use Regular Expressions

                      Do you know or can you surmise if it uses any of the following?
                      Take a guess otherwise - it would be a better guess than mine.


                      The RegexOptions Enumeration contains:

                      Multiline
                      ExplicitCapture
                      Singleline
                      IgnorePatternWh itespace
                      ECMAScript
                      CultureInvarian t

                      Thanks again


                      Comment

                      • jamil@onepost.net

                        #12
                        Re: need a reg expression

                        On Sun, 13 Apr 2008 09:55:06 -0400, "AAaron123"
                        <aaaron123@road runner.comwrote :
                        >Thanks for all the help.
                        No problem.
                        >Besides what you showed me my underlying problem was the string contained
                        >CR(13) for line endings.
                        >I checked a RichTextBox.Tex t and it contained LF for line endings.
                        >I expected CRLF since I thought the was the way of Windows.
                        >
                        >Any way I replace CR wit LF and replace works OK now.
                        >
                        >Must be Regex looks for LF.
                        >Sound right to you?
                        In UNIX, yes. A line termination is a LF. In Windows typically, no. A
                        line termination is typically a carriage return and linefeed
                        combination. I've not tested this under .NET's engine, but it could be
                        using UNIX style line terminations.
                        >I'd like my code to act the same as
                        >VS2008/Edit/Find In Files/Use Regular Expressions
                        >
                        >Do you know or can you surmise if it uses any of the following?
                        >Take a guess otherwise - it would be a better guess than mine.
                        I do not yet own VS2008 (I saw no good reason to upgrade from 2005).
                        I'm not sure if this particular sample was included with VS2005,
                        because I have no samples installed.

                        If you could give a summary of what it is you're trying to accomplish,
                        or perhaps someone else could help out on this question.

                        Comment

                        • AAaron123

                          #13
                          Re: need a reg expression


                          <jamil@onepost. netwrote in message
                          news:k59604tt3k hthan2vls5b8voh 6toei5ae7@4ax.c om...
                          On Sun, 13 Apr 2008 09:55:06 -0400, "AAaron123"
                          <aaaron123@road runner.comwrote :
                          >
                          >>Thanks for all the help.
                          >
                          No problem.
                          >
                          >>Besides what you showed me my underlying problem was the string contained
                          >>CR(13) for line endings.
                          >>I checked a RichTextBox.Tex t and it contained LF for line endings.
                          >>I expected CRLF since I thought the was the way of Windows.
                          >>
                          >>Any way I replace CR wit LF and replace works OK now.
                          >>
                          >>Must be Regex looks for LF.
                          >>Sound right to you?
                          >
                          In UNIX, yes. A line termination is a LF. In Windows typically, no. A
                          line termination is typically a carriage return and linefeed
                          combination. I've not tested this under .NET's engine, but it could be
                          using UNIX style line terminations.
                          >
                          >>I'd like my code to act the same as
                          >>VS2008/Edit/Find In Files/Use Regular Expressions
                          >>
                          >>Do you know or can you surmise if it uses any of the following?
                          >>Take a guess otherwise - it would be a better guess than mine.
                          >
                          I do not yet own VS2008 (I saw no good reason to upgrade from 2005).
                          I'm not sure if this particular sample was included with VS2005,
                          because I have no samples installed.
                          >
                          If you could give a summary of what it is you're trying to accomplish,
                          or perhaps someone else could help out on this question.
                          No need.
                          You solve my problem.
                          Mostly just curious now.
                          Thanks


                          Comment

                          Working...