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. Regular Expressions
  4. Pattern

Pattern

Scheduled Pinned Locked Moved Regular Expressions
regexhelp
15 Posts 5 Posters 39 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 byka

    examples: Testing-123456_filename.xls - valid My-1234568_filename.txt- not valid (because 7 digits) Testring-123456-filename.dat- not valid( missing _) filename.txt - not valid( missing _ and - ) Testring_123456_filename.dat- not valid( missing -)

    P Offline
    P Offline
    Pete OHanlon
    wrote on last edited by
    #6

    This doesn't match what you specified originally. You stated that it should be 100 characters, but My-, for instance, isn't. So, which set of rules are correct?

    I'm not a stalker, I just know things. Oh by the way, you're out of milk.

    Forgive your enemies - it messes with their heads

    My blog | My articles | MoXAML PowerToys | Onyx

    B 1 Reply Last reply
    0
    • P Pete OHanlon

      This doesn't match what you specified originally. You stated that it should be 100 characters, but My-, for instance, isn't. So, which set of rules are correct?

      I'm not a stalker, I just know things. Oh by the way, you're out of milk.

      Forgive your enemies - it messes with their heads

      My blog | My articles | MoXAML PowerToys | Onyx

      B Offline
      B Offline
      byka
      wrote on last edited by
      #7

      clarification:it can be up to 100 charachers

      P 1 Reply Last reply
      0
      • L Luc Pattyn

        -\d{6}_

        :)

        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

        B Offline
        B Offline
        byka
        wrote on last edited by
        #8

        If I used you pattern I am getting all invalid returns Here my code and test cases: Public Function Verify(ByVal myFileName As String) Dim Pattern As String = "-d{6}_" '"([a-zA-z]{100}\d{6}[a-zA-z]{1,})" Dim MyRegex As New RegularExpressions.Regex(Pattern, RegularExpressions.RegexOptions.IgnoreCase) Return MyRegex.IsMatch(myFileName, 0) End Function Testing scenario: If Verify("Granic-012345_Test-Granic.txt") Then ' should be valid MessageBox.Show("valid") Else MessageBox.Show("Not valid") End If If Verify("TESTTING-123456-Norman_NDtest1.dat") Then ' should be not valid MessageBox.Show("valid") Else MessageBox.Show("Not valid") End If If Verify("GRANIC-123456_jayson.xls") Then ' should be not valid MessageBox.Show("valid") Else MessageBox.Show("Not valid") End If If Verify("incoming-testfile.txt") Then ' should be not valid MessageBox.Show("valid") Else MessageBox.Show("Not valid") End If If Verify("Testing-474948_filename.txt") Then ' should be valid MessageBox.Show("valid") Else MessageBox.Show("Not valid") End If

        L 1 Reply Last reply
        0
        • B byka

          If I used you pattern I am getting all invalid returns Here my code and test cases: Public Function Verify(ByVal myFileName As String) Dim Pattern As String = "-d{6}_" '"([a-zA-z]{100}\d{6}[a-zA-z]{1,})" Dim MyRegex As New RegularExpressions.Regex(Pattern, RegularExpressions.RegexOptions.IgnoreCase) Return MyRegex.IsMatch(myFileName, 0) End Function Testing scenario: If Verify("Granic-012345_Test-Granic.txt") Then ' should be valid MessageBox.Show("valid") Else MessageBox.Show("Not valid") End If If Verify("TESTTING-123456-Norman_NDtest1.dat") Then ' should be not valid MessageBox.Show("valid") Else MessageBox.Show("Not valid") End If If Verify("GRANIC-123456_jayson.xls") Then ' should be not valid MessageBox.Show("valid") Else MessageBox.Show("Not valid") End If If Verify("incoming-testfile.txt") Then ' should be not valid MessageBox.Show("valid") Else MessageBox.Show("Not valid") End If If Verify("Testing-474948_filename.txt") Then ' should be valid MessageBox.Show("valid") Else MessageBox.Show("Not valid") End If

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #9

          that is a useless message: a lot of code, but no results. and code should be in PRE tags, not CODE tags. it would help if you would copy my suggestion correctly. :|

          Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

          M 1 Reply Last reply
          0
          • B byka

            clarification:it can be up to 100 charachers

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #10

            Then try this:

            [a-zA-Z]{1,100}-\d{6}_[a-zA-Z]{1,}

            I'm not a stalker, I just know things. Oh by the way, you're out of milk.

            Forgive your enemies - it messes with their heads

            My blog | My articles | MoXAML PowerToys | Onyx

            B 1 Reply Last reply
            0
            • P Pete OHanlon

              Then try this:

              [a-zA-Z]{1,100}-\d{6}_[a-zA-Z]{1,}

              I'm not a stalker, I just know things. Oh by the way, you're out of milk.

              Forgive your enemies - it messes with their heads

              My blog | My articles | MoXAML PowerToys | Onyx

              B Offline
              B Offline
              byka
              wrote on last edited by
              #11

              WORKING!!!!!!!!!! THANK YOU :)

              1 Reply Last reply
              0
              • L Luc Pattyn

                that is a useless message: a lot of code, but no results. and code should be in PRE tags, not CODE tags. it would help if you would copy my suggestion correctly. :|

                Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                M Offline
                M Offline
                musefan
                wrote on last edited by
                #12

                but if he kept the \ then there would be compile time errors, so it is best to just not put it in than to work out why it causes an issue, right? :~

                I may or may not be responsible for my own actions

                L 1 Reply Last reply
                0
                • M musefan

                  but if he kept the \ then there would be compile time errors, so it is best to just not put it in than to work out why it causes an issue, right? :~

                  I may or may not be responsible for my own actions

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #13

                  Wrong. if it is to be a string literal (not stated explicitly), then it would be OK in some languages such as VB.NET (not specified), it would not be OK in some others such as C, and it would be OK in C# only when using a preceeding @ sign or doubling the \. And that is exactly why I didn't put any double quotes at all, I only specified what the content of the string had to be. I trust people know their programming language of choice well enough to turn that into a string literal if that is what they need. :)

                  Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                  M 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    Wrong. if it is to be a string literal (not stated explicitly), then it would be OK in some languages such as VB.NET (not specified), it would not be OK in some others such as C, and it would be OK in C# only when using a preceeding @ sign or doubling the \. And that is exactly why I didn't put any double quotes at all, I only specified what the content of the string had to be. I trust people know their programming language of choice well enough to turn that into a string literal if that is what they need. :)

                    Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                    Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                    M Offline
                    M Offline
                    musefan
                    wrote on last edited by
                    #14

                    Now how did I know VB was going to come back and bite me on the ass for that one :doh:

                    I may or may not be responsible for my own actions

                    1 Reply Last reply
                    0
                    • B byka

                      Could you help me write a pattern for Regex. I need to look for file name with this pattern: string(no number; only 100 characters)-6digitnumber_string

                      S Offline
                      S Offline
                      Shahan Ayyub
                      wrote on last edited by
                      #15

                      It would be better for us if you could come up with some examples ? As I understood from your given information, this is required to you:

                      ^\D{5}\-\d{6}_\D{1,}$

                      So it should match with this kind of samples:

                      aaaaa-666666_a

                      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