Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expressions 1

Status
Not open for further replies.

Swi

Programmer
Feb 4, 2002
1,963
0
36
US
Could someone elaborate as to why the following code does not work? It is not flagged names that are last name, first name. Thank you.

Code:
    '-- pick apart name by removing prefix,
    '     suffix, and title
    strName = Trim(fncExtractSuffix(strName))
    strName = Trim(fncExtractPrefix(strName))
    strName = Trim(fncExtractTitle(strName))
    mobjRegExp.Global = True
    '-- check for last, first combo (Doe, Jo
    '     hn) ----
    mobjRegExp.Pattern = "[^ \f\n\r\t\v\,]+\,\s+\S+ "

    If mobjRegExp.Test(strName) = True Then
        Call subParseLastFirst(strName)

Swi
 
[1] There is a spurious space at the end of the pattern which should not be intended, a typo?
[tt] mobjRegExp.Pattern = "[^ \f\n\r\t\v\,]+\,\s+\S[highlight]+"[/highlight][/tt]

[2] And then, it matches "Doe, Jo\r\nhn" with a line feed after Jo which shouldn't be intended. It succeeds because the it is not instructed to match the whole _trimmed_ string. It should really better be this, I guess-and then the global property is irrelevant.
[tt] mobjRegExp.Pattern = "[red]^[/red][^ \f\n\r\t\v\,]+\,\s+\S+[red]$[/red]"[/tt]

[3] comma can be put literally without escaping. You can sure "escape" it too.

[4] And then exotic case, such as "Doe, J,oh9n" would still be matched. Area for tightening...
 
Thank you for the response and explantion. It works great. Thank you again.

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top