[thelist] Easy VBscript Question: relative expressions

Anthony Baratta Anthony at Baratta.com
Thu Jul 10 15:45:51 CDT 2003


At 01:07 PM 7/10/2003, Kiddy, Jon wrote:
>Need VBscript that can do the following; efficiency is key.
>
>Takes a string:  "Smith,-John2x2.jpg" or "Smith,-John2.jpg"
>And change it to:  "John Smith"

This is not tested, but should be a close approximation of what you are 
looking for.

     varText = Trim(varString)

     '' Creating RegEx Object
     Set regEx = New RegExp
     regEx.IgnoreCase = True
     regEx.Global = True

     ''Finding First Pattern
     regEx.Pattern = "(\"[^\,]+\,\-)"
     Set Matches = regEx.Execute(varText)

     For Each Match in Matches
         LastName = Match.Value
     Next

     ''Finding Second Pattern
     regEx.Pattern = "(,-[^0-9]+[0-9])"
     Set Matches = regEx.Execute(varText)

     For Each Match in Matches
         FirstName = Match.Value
     Next


-- 
Anthony Baratta
President
Keyboard Jockeys

"Conformity is the refuge of the unimaginative."



More information about the thelist mailing list