Regular expression: I don't find right pattern

Leen

Registered User.
Local time
Today, 12:44
Joined
Mar 15, 2007
Messages
56
Hi,
I have a problem using regular expressions, in which I don't find the correct pattern to return the right values.

I have a table, in which in the records, names are stored. For example:
Street Alex
Victorian Runway
etc.

The goal is to check whether the user has filled in the names using a "mixed case" rule: so each word has to start with a capital and followed by small letters.

My code works on the opposite: it looks were there is a word starting with a little case and if so, it returns "False" else, it is true:

Code:
Function regexpCase(astring As String) As String 'use mixed cases via regular expressions
    Dim regEx As Object
    Set regEx = CreateObject("vbscript.regexp")
    
    With regEx
        .Pattern = "(\b[a-z][a-z]*\b)" 'not a mixed case
        .Ignorecase = False
        .Global = False
    End With
    
    Set matches = regEx.Execute(astring)
    If matches.Count = 0 Then
        regexpCase = astring 'no error, then none of the strings start with a lower Case
    Else
        regexpCase = vbNullString 'error, one of the strings does not start with a lower Case
    End If
    
    Set matches = Nothing
    Set regEx = Nothing
End Function

However, this works but following values are also returned as false:
D'soui Street
S'vanaah Kai
So when there is an apostrophe is it seen as wrong, while these names are right.

How can I change the pattern to overcome this problem?
Thanks for any help!
Leen
 
why not use one of the excelent Functions to be found here called Proper.

Input

susan o'smith

output
Susan O'Smith
 
Because actually, in this database (for streetnames),
Susan O'Smith is not right,
susan o'smith is also not right,

but Susan O'smith is wright (so when a part of a streetname contains a apostrophe, it does not have to have an upper case.
 

Users who are viewing this thread

Back
Top Bottom