Results 1 to 2 of 2
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    regular Expressions - case Study 1 (Word97/SR2)

    For those who want to idle away the night time, here's a typical problem for Regular Expressions:

    From the text stream below, write VBA code to isolate the alphabetic strings (which could then be passed to a statistical machine, heh heh!).


    1) The alphabet is the regular a-z and A-Z
    2) The space character is the regular asc(032)
    3) All other characters are considered to be punctuation characters.
    4) Words are generally delimited by space characters.
    5) A punctuation character adjacent to alphabetics should be retained.

    Examples of Words:

    <pre>Accessories
    Tooling
    Also
    Chillers
    Equip
    N/C (rule 5)
    </pre>


    <pre>Accessories & Tooling, See Tooling & Accessories
    Agitators, See Chemical, Petroleum, Gas & Processing Equipment
    Air Compressors & Accessories
    Air Conditioning & Water Chiller Equipment, (Also See Chillers)
    Air Coolers, See Chemical, Petroleum, Gas & Processing Eq, Heat Exchangers, Air Coolers
    Air Cylinders, See Specific Air Compressor Listing
    Air Dryers, See Air Compressors, Dryers
    Air Feeders, See Coil Handling Equipment Section, Feeders
    Air Separators
    Air Vacuum Pumps, Dry, See Air Compressors Vacuum Pumps, Dry
    Automatic Screw Machines & Chuckers, (Also See Cnc & Nc Machinery & Equip.,Automatics)
    Automatic Screw Machines & Chuckers, Cnc & N/C, See Cnc & N/C Machinery & Equip.
    </pre>


    Give me time to come up with a solution before posting your examples. That way your examples will be seen as vast improvements on mine!

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: regular Expressions - case Study 1 (Word97/SR2

    OK. here's a start. I have to work more on the embedded punctuation characters. I stole the basis for the function from some of the documentation pages listed in a previous thread.

    <pre>Public Function RegExp2(patrn, strng)
    Dim regex As regExp
    Dim match, matches, retstr
    Set regex = New regExp
    regex.Pattern = patrn
    regex.IgnoreCase = True
    regex.Global = True
    Set matches = regex.Execute(strng)
    For Each match In matches
    retstr = retstr & match.Value & vbCrLf
    Next
    RegExp2 = retstr
    'Sub TESTRegExp2()
    ' MsgBox RegExp2("[a-z]+", "Accessories & Tooling, See Tooling & Accessories")
    '' need a better pattern for this example
    ' MsgBox RegExp2("[a-z]+", "Automatic Screw Machines & Chuckers, Cnc & N/C, See Cnc & N/C Machinery & Equip.")
    ' MsgBox RegExp2("[a-z]+/[a-z]+", " Machines & Chuckers, Cnc & N/C, See Cnc & N/C Machinery & Equip.")
    'End Sub
    End Function

    </pre>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •