Results 1 to 2 of 2

Thread: Use Regular Expression to count occurrence of

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091

    Use Regular Expression to count occurrence of

    I need to count the number of:

    Alpha
    Numeric
    Other (non alpha-numeric, like symbols)
    Upper Alpha
    Lower Alpha

    in a string.

    Can Regular Expression be used of this purpose? It's okay if they're in separate function, but I need to somehow get the counts of each of the above. Any help would be appreciated.

    Visual Studio 2010

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

    Re: Use Regular Expression to count occurrence of

    try this:

    vb Code:
    1. Dim testStr As String = "Can Regular Expression be used of this purpose? It's okay if they're in separate function, but I need to somehow get the counts of each of the above. Any help would be appreciated. 0123456789"
    2. MsgBox(New Regex("[A-Za-z]").Matches(testStr).Count.ToString) 'Alpha
    3. MsgBox(New Regex("\d").Matches(testStr).Count.ToString) 'Numeric
    4. MsgBox(New Regex("[^A-Za-z\d]").Matches(testStr).Count.ToString) 'Other
    5. MsgBox(New Regex("[A-Z]").Matches(testStr).Count.ToString) 'Upper Alpha
    6. MsgBox(New Regex("[a-z]").Matches(testStr).Count.ToString) 'Lower Alpha

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