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. Regex problem

Regex problem

Scheduled Pinned Locked Moved C#
regexhelptutorialquestion
6 Posts 3 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.
  • Y Offline
    Y Offline
    Yaakov Davis
    wrote on last edited by
    #1

    I need that Regex won't return match if the string starts with another substring, for example "abc". In detail, "abcde" shouldn't match, but "abg", "gbc" and "afcgr" should match. I know the [^abcde] syntax that works for characters, but I couldn't figure out way for substrings. It is possible to do this with Regex? I need it to be done through Regex, not String class methods. Thanks.

    L 1 Reply Last reply
    0
    • Y Yaakov Davis

      I need that Regex won't return match if the string starts with another substring, for example "abc". In detail, "abcde" shouldn't match, but "abg", "gbc" and "afcgr" should match. I know the [^abcde] syntax that works for characters, but I couldn't figure out way for substrings. It is possible to do this with Regex? I need it to be done through Regex, not String class methods. Thanks.

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

      Use explicit capture and the following: (abc.*)|(?a.*) You can use backtracking too, but i dont really understand it, the above way does the same, kinda :p top secret
      Download xacc-ide 0.0.3 now!
      See some screenshots

      Y 1 Reply Last reply
      0
      • L leppie

        Use explicit capture and the following: (abc.*)|(?a.*) You can use backtracking too, but i dont really understand it, the above way does the same, kinda :p top secret
        Download xacc-ide 0.0.3 now!
        See some screenshots

        Y Offline
        Y Offline
        Yaakov Davis
        wrote on last edited by
        #3

        I think you missed the point. "abc" should not match. I want to match any combination of three characters, except the above sequence. I can do it as well with two chars. For example, if i want to match anything except "ab", i can use (?:a[^b])|(?:[^a].). But when it comes to three or more characters, i find no way. Maybe I miss something. Thanks.

        T L Y 3 Replies Last reply
        0
        • Y Yaakov Davis

          I think you missed the point. "abc" should not match. I want to match any combination of three characters, except the above sequence. I can do it as well with two chars. For example, if i want to match anything except "ab", i can use (?:a[^b])|(?:[^a].). But when it comes to three or more characters, i find no way. Maybe I miss something. Thanks.

          T Offline
          T Offline
          TyronX
          wrote on last edited by
          #4

          "[^(abcd)]+" seems to be working a better way would be: "^(?!abcd).+" (I'm not sure if (?!x) is a valid expression in the C# Regexes)

          1 Reply Last reply
          0
          • Y Yaakov Davis

            I think you missed the point. "abc" should not match. I want to match any combination of three characters, except the above sequence. I can do it as well with two chars. For example, if i want to match anything except "ab", i can use (?:a[^b])|(?:[^a].). But when it comes to three or more characters, i find no way. Maybe I miss something. Thanks.

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

            sb777 wrote: Maybe I miss something. Perhaps :) It is infact matched just not returned, well at least not as a named group. Al you have to do is check is Groups["good"].Success. As long as your precedence is correct, you can match and 'eleminate' alot of data at once. top secret
            Download xacc-ide 0.0.3 now!
            See some screenshots

            1 Reply Last reply
            0
            • Y Yaakov Davis

              I think you missed the point. "abc" should not match. I want to match any combination of three characters, except the above sequence. I can do it as well with two chars. For example, if i want to match anything except "ab", i can use (?:a[^b])|(?:[^a].). But when it comes to three or more characters, i find no way. Maybe I miss something. Thanks.

              Y Offline
              Y Offline
              Yaakov Davis
              wrote on last edited by
              #6

              TyronX, yous second suggestion did answered my question. thanks a lot. BTW, the first one isn't correct. leppie, Your suggestion could also fit in another constraints, but thanks for the new information.

              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