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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Regular Expresion

Regular Expresion

Scheduled Pinned Locked Moved C#
regex
7 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.
  • O Offline
    O Offline
    ONeil Tomlinson
    wrote on last edited by
    #1

    Hi I want to write a regular expression that will match when there is no "XXSP" at the begining of the string eg "XXSPPaabbcc1234" = No Match eg "XaXSPPaabbcc1234" = Match Thanks

    OriginalGriffO M 2 Replies Last reply
    0
    • O ONeil Tomlinson

      Hi I want to write a regular expression that will match when there is no "XXSP" at the begining of the string eg "XXSPPaabbcc1234" = No Match eg "XaXSPPaabbcc1234" = Match Thanks

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Why use a regular expression?

      if ((s.Length >= 5) && (!s.StartsWith("XXSP")
      {
      //Match
      }

      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      O 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Why use a regular expression?

        if ((s.Length >= 5) && (!s.StartsWith("XXSP")
        {
        //Match
        }

        No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

        O Offline
        O Offline
        ONeil Tomlinson
        wrote on last edited by
        #3

        I need to use a Regular expression (im passing it to a Business rule engine)

        OriginalGriffO 1 Reply Last reply
        0
        • O ONeil Tomlinson

          I need to use a Regular expression (im passing it to a Business rule engine)

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Isn't it just "^XXSP" as in:

                  string s1 = "XXSPHello";
                  string s2 = "XaSPGoodbye";
                  Regex r = new Regex(@"^XXSP");
                  if (r.Match(s1).Success)
                      {
                      MessageBox.Show(s1);
                      }
                  if (r.Match(s2).Success)
                      {
                      MessageBox.Show(s2);
                      }
          

          No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          M 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Isn't it just "^XXSP" as in:

                    string s1 = "XXSPHello";
                    string s2 = "XaSPGoodbye";
                    Regex r = new Regex(@"^XXSP");
                    if (r.Match(s1).Success)
                        {
                        MessageBox.Show(s1);
                        }
                    if (r.Match(s2).Success)
                        {
                        MessageBox.Show(s2);
                        }
            

            No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

            M Offline
            M Offline
            MidwestLimey
            wrote on last edited by
            #5

            That will match any string starting with XXSP.

            10110011001111101010101000001000001101001010001010100000100000101000001000111100010110001011001011

            1 Reply Last reply
            0
            • O ONeil Tomlinson

              Hi I want to write a regular expression that will match when there is no "XXSP" at the begining of the string eg "XXSPPaabbcc1234" = No Match eg "XaXSPPaabbcc1234" = Match Thanks

              M Offline
              M Offline
              MidwestLimey
              wrote on last edited by
              #6

              You can't use a Regex to not find a pattern, per se, as there are too many ways to not match. Instead you want to match and exclude anything that begins with XXSP. This should do the trick:

              ^((X[^X])|(XX[^S])|(XXS[^P])).*$

              10110011001111101010101000001000001101001010001010100000100000101000001000111100010110001011001011

              O 1 Reply Last reply
              0
              • M MidwestLimey

                You can't use a Regex to not find a pattern, per se, as there are too many ways to not match. Instead you want to match and exclude anything that begins with XXSP. This should do the trick:

                ^((X[^X])|(XX[^S])|(XXS[^P])).*$

                10110011001111101010101000001000001101001010001010100000100000101000001000111100010110001011001011

                O Offline
                O Offline
                ONeil Tomlinson
                wrote on last edited by
                #7

                Thanks dude that worked ;)

                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