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

RegEx

Scheduled Pinned Locked Moved C#
regexquestion
6 Posts 2 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.
  • P Offline
    P Offline
    Paul Unsworth
    wrote on last edited by
    #1

    Hey Guys I'm using the RegEx to do some pattern matching, but I'm after finding one of 2 specific strings. At the moment I'm using Regex reg1 = new Regex("FIRST[ ]+STRING");Regex reg2 = new Regex("SECOND[ ]+STRING"); Is there a way I could get the Regular Expression to say match exact string A OR exact string B in the same statement? (eg Regex exp = new Regex("ThisString or ThisString"); Thank you in advance :-D

    oooo, the Jedi's will feel this one....

    OriginalGriffO 2 Replies Last reply
    0
    • P Paul Unsworth

      Hey Guys I'm using the RegEx to do some pattern matching, but I'm after finding one of 2 specific strings. At the moment I'm using Regex reg1 = new Regex("FIRST[ ]+STRING");Regex reg2 = new Regex("SECOND[ ]+STRING"); Is there a way I could get the Regular Expression to say match exact string A OR exact string B in the same statement? (eg Regex exp = new Regex("ThisString or ThisString"); Thank you in advance :-D

      oooo, the Jedi's will feel this one....

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

      Regex exp = new Regex("(ThisString)|(ThatString)");

      Will do it nicely.

      You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

      "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

      P 1 Reply Last reply
      0
      • P Paul Unsworth

        Hey Guys I'm using the RegEx to do some pattern matching, but I'm after finding one of 2 specific strings. At the moment I'm using Regex reg1 = new Regex("FIRST[ ]+STRING");Regex reg2 = new Regex("SECOND[ ]+STRING"); Is there a way I could get the Regular Expression to say match exact string A OR exact string B in the same statement? (eg Regex exp = new Regex("ThisString or ThisString"); Thank you in advance :-D

        oooo, the Jedi's will feel this one....

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

        Before I forget - have a look at Expresso[^] - it examines, creates and explains regular expressions. It works, it helps you understand how they work, and it's free.

        You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

        "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

        P 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Regex exp = new Regex("(ThisString)|(ThatString)");

          Will do it nicely.

          You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

          P Offline
          P Offline
          Paul Unsworth
          wrote on last edited by
          #4

          Thats it??? :doh: So simple. I'm kicking myself now. Thank you.

          oooo, the Jedi's will feel this one....

          OriginalGriffO 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Before I forget - have a look at Expresso[^] - it examines, creates and explains regular expressions. It works, it helps you understand how they work, and it's free.

            You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

            P Offline
            P Offline
            Paul Unsworth
            wrote on last edited by
            #5

            Excellent. Thanks. I'm new to regular expressions, and they appear very alien so far. Muchas Gracias :-D

            oooo, the Jedi's will feel this one....

            1 Reply Last reply
            0
            • P Paul Unsworth

              Thats it??? :doh: So simple. I'm kicking myself now. Thank you.

              oooo, the Jedi's will feel this one....

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

              You're welcome - technically you don't need the brackets, but I always feel they help to make it more readable (if a regex can be described as readable... :laugh: )

              You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

              "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

              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