Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Urgent Regualr Expression Help Needed

Urgent Regualr Expression Help Needed

Scheduled Pinned Locked Moved C#
tutorialcomregexhelp
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brian Van Beek
    wrote on last edited by
    #1

    Hello, I need to know how to only match if a word does not appear before the selected word. For example, I have the sentence "there is a brown fox over there". The word I'm trying to match would be, say "fox". However, I only want to match "fox" if the word "brown" does not appear directly before it. Any help would be greatly appreciated. So the sentence above would not match, however the sentence "there is a fox over there" would match. Thanks folks! Brian Van Beek Here's my boring blog! [^] -- modified at 11:15 Monday 17th October, 2005

    L 1 Reply Last reply
    0
    • B Brian Van Beek

      Hello, I need to know how to only match if a word does not appear before the selected word. For example, I have the sentence "there is a brown fox over there". The word I'm trying to match would be, say "fox". However, I only want to match "fox" if the word "brown" does not appear directly before it. Any help would be greatly appreciated. So the sentence above would not match, however the sentence "there is a fox over there" would match. Thanks folks! Brian Van Beek Here's my boring blog! [^] -- modified at 11:15 Monday 17th October, 2005

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      [^brown](\s|\t)+fox That works

      B L 2 Replies Last reply
      0
      • L Lost User

        [^brown](\s|\t)+fox That works

        B Offline
        B Offline
        Brian Van Beek
        wrote on last edited by
        #3

        thanks! Brian Van Beek Here's my boring blog! [^]

        1 Reply Last reply
        0
        • L Lost User

          [^brown](\s|\t)+fox That works

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          Greeeg wrote:

          That works

          I highly doubt that! [^brown] means 'one character NOT any of (b,r,o,w,n)'. xacc-ide 0.0.99-preview5 now with C#, C, IL, XML, Nemerle, IronPython and Boo highlighting support!

          L 1 Reply Last reply
          0
          • L leppie

            Greeeg wrote:

            That works

            I highly doubt that! [^brown] means 'one character NOT any of (b,r,o,w,n)'. xacc-ide 0.0.99-preview5 now with C#, C, IL, XML, Nemerle, IronPython and Boo highlighting support!

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Well, to be honest I was not completely sure about that. :-O How to do this correctly? I tried (word){0}, but that doesn't work.

            D L 2 Replies Last reply
            0
            • L Lost User

              Well, to be honest I was not completely sure about that. :-O How to do this correctly? I tried (word){0}, but that doesn't work.

              D Offline
              D Offline
              Daniel Turini
              wrote on last edited by
              #6

              You need to use a Negative Lookbehind. (?<!brown)\s+fox

              1 Reply Last reply
              0
              • L Lost User

                Well, to be honest I was not completely sure about that. :-O How to do this correctly? I tried (word){0}, but that doesn't work.

                L Offline
                L Offline
                leppie
                wrote on last edited by
                #7

                Greeeg wrote:

                How to do this correctly?

                I would use explicit captures, eg:

                (?<brown>brown)\s+(?<fox>fox)

                Match m = Regex.Match();
                return m.Groups["brown"].Success && !m.Groups["fox"].Success;

                or even easier:

                return !Match("brown\s+fox");

                xacc-ide 0.0.99-preview5 now with C#, C, IL, XML, Nemerle, IronPython and Boo highlighting support!

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups