Results 1 to 6 of 6

Thread: regex question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    regex question

    i have a string (the letters will never be in the same order):

    TFTADFDAAFDADADDAFFDTFFTDFTFTDTTAFDAFADTAAATFDTADAFFTFTDDFDAFFTAT

    1) i know it is always going to 65 characters (no numbers)
    2) it will only have the letters ADFT

    i want to loop through each row of data and check if the data contains this.

    Code:
    System.Text.RegularExpressions.Regex.IsMatch()
    is this possible? if so, i need some help writing the expression.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: regex question

    vb Code:
    1. Dim testStr As String = "TFTADFDAAFDADADDAFFDTFFTDFTFTDTTAFDAFADTAAATFDTADAFFTFTDDFDAFFTAT"
    2.  
    3. Dim rx As New Regex("(A|D|F|T)+")
    4. MsgBox(rx.Match(testStr).Length)

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: regex question

    how was that? does that work ok for you?

    all it does is test for those 4 characters + then shows the match length in the msgbox (which should always be 65).

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: regex question

    Hey,

    What about something like this:

    Code:
            If Regex.IsMatch(inputString, "[ADFT]{65,}") Then
                MessageBox.Show("Match")
            Else
                MessageBox.Show("No Match")
            End If
    It will obviously match if there is something either side of the string as well, but should give the OP what he wants.

    Gary

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: regex question

    both seem to work.
    i like gep13 suggestion because that is exactly how i would be checking the string for a match.

    what does the comma after the 65 mean?

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: regex question

    It is possible to specify a range of matches, i.e. match any number between x and y. i.e. [ADFT]{65,100}, would match any number of characters between 65 and 100. The fact that there is nothing after the comma means it will match exactly 65.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width