[AccessD] A2003: Extracting strings

Steve Erbach erbachs at gmail.com
Fri Nov 18 06:32:05 CST 2005


Marty,

You know, I looked for the phrase "regular expression" in the "Help" but
found nothing but the usual references to expressions: expression builder,
expressions in queries, jet expression sandbox mode, etc. After getting your
very helpful hint, I looked on my Safari Bookshelf in the "VBScript in a
Nutshell" book, and voilà! There she is! RegExp object and all its methods
and properties. Thank you.

Has that object been available to me all this time? I mean, since Access 97
or 2000?

Steve Erbach
Neenah, WI

On 11/17/05, MartyConnelly <martyconnelly at shaw.ca> wrote:
>
> How about a Regular Expression function
>
> '?getDateRegEx("aaaa 12-12-2005 888hh")
> '?getDateRegEx("aaaa 13-13-04 888hh")
> '?getDateRegEx("aaaa 12-12-04 888hh")
>
> Public Function getDateRegEx(ByVal sValue As String) As Variant
>
> 'need reference to Microsoft VBScript Regular Expressions 5.5,
> ' or Set r = CreateObject("vbscript.regexp")
> Dim x As Integer
> Dim r As RegExp
> Dim buf As String
> Dim match As Object
> Dim matches As Object
>
> getDateRegEx = Null
> 'throws a null into a bad date like 13-13-2005
>
> Set r = New RegExp
> r.Pattern = "\d{1,2}[-]+\d{1,2}[-]+\d{1,4}"
> ' r.Pattern = "((?:19|20)\d\d)[- /.](0[1-9]|1[012])[-
> /.](0[1-9]|[12][0-9]|3[01][- /.](?:19|20)\d\d))"
>
> Set matches = r.Execute(sValue)
> For Each match In matches
> Debug.Print match.Value
> On Error Resume Next
> getDateRegEx = CDate(match.Value)
> Next match
> Set matches = Nothing
> Set r = Nothing
> End Function
>
>
>
> Steve Erbach wrote:
>
> >Dear Group,
> > Lets say you have a note field in a table into which your users have
> been
> >entering text notes that include dates in various formats (9-1-05,
> 10/12/04,
> >8/3/2004, etc.) as well as the text. What I'd like to do is extract those
> >dates from the note field and stuff them into a bona fide date field.
>



More information about the AccessD mailing list