Results 1 to 11 of 11
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wildcard Search (any)

    Here's a FindText string that finds the last line (or most of it) of an address block (US postal destinations) in document:

    FindText="[A-Z][A-z]{1,20},[ ]{1,2}[A-z]{1,12}[ ]{1,3}[0-9-]{5,10}"

    Los Angeles, CA 91234-4321
    or
    San Francisco, California 91234-4322

    The problem is it won't find the line if the State consists of two words, like New Mexico, Rhode Island, etc.

    Can YOU help me out with a fix?

    I think I'd could write a successful wildcard search if Word supported a wildcard for "zero or 1 occurrence",
    but maybe it can be done...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Wildcard Search (any)

    If you plan to collapse the selection after the find, this should work:

    [A-z ]{1,20},[ ]{1,2}[A-z ]{1,12}[0-9-]{5,10}

    It works by incorporating the space prior to the zip code into the state name criterion. (Maybe the 12 should be changed to a higher number, but I didn't text extensively.)

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcard Search (any)

    Jefferson,
    I tried that, but it doesn't work. But if tried it and it DOES, then maybe I better
    give it another go...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Wildcard Search (any)

    I tested interactively with Santa Fe, New Mexico 98765 and it worked for that. Just retested, still works. Remember to collapse the selection between finds or it keeps finding smaller and smaller parts of the found text until it runs through the city name completely.

    (Note: Just tested with North Dakota, and you need to increase the {1,12} parameter to maybe {1,15} to cover that one.)

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcard Search (any)

    Ok, I see now. The space in [A-z ] not only accounts for the space between
    city or State names, but also the space(s) between State and zip!

    That drove me nuts! So, I just had to try this again with that idea in mind.
    I wanted to eliminate the need to collapse the selection, but the two or three
    part names won't allow it.

    So, here's what I've got:

    [A-Z][A-z -]{1,20},[ ]{1,2}[A-Z][A-z ]{1,16}[0-9-]{5,10}

    The [A-Z]'s are my attempt to eliminate the selection collapse. Even though
    it reduces the number of finds per line, the two or three part names make it
    necessary. Oh, where are thou, RegEx!
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcard Search (any)

    Tow of the test cases used during the making of this wildcard search:

    Bald Head Island, North Carolina 98765-0987

    Winston-Salem, North Carolina 98765-0987
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcard Search (any)

    Hi Kevin:
    Interesting problem. Are you going to do a Replace or ReplaceAll with it? If you are, then you don't have to collapse it. You can also use:
    [A-Z][a-z]{1,}*[0-9]{5}-[0-9]{4}
    in the Find box.

    Does it help if you use:
    [^13][A-Z][a-z]{1,}*[0-9]{5}-[0-9]{4}

    This will find only the whole string, but also includes the pargraph mark before it. I guess I'm trying to see if there is some other way to accomplish the ultimate goal.

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcard Search (any)

    Phil,
    I like the way you get into the spirit of the issue!

    No, I'm doing no replace. Just searching. This find is a part of the old
    ExtractAddress function I published in the VBA forum years ago. I've
    refined it a bit and needed a better wildcard search as the previous one
    had some limitations. The idea is to find an address in a document no
    matter what paragraph or table formatting surrounds it. The Word built-in
    routine does not meet our needs.

    I don't think your [0-9]{5}-[0-9]{4} will work because there isn't always a hyphen
    in the zip. Some of our zips show up as 98765, 98765-0001 or 987650001.

    Also, a preceding ^13 is assuming the line begins with a para mark. Some lines
    begin with a tab, others a vertical tab, etc.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcard Search (any)

    Hi Kevin:
    Boy, this is a challenge. I don't think that there is a way to do this directly (although I haven't given up). My brain hurts from thinking (this is my second day of retirement & I've forgotten how <img src=/S/grin.gif border=0 alt=grin width=15 height=15>). Two thoughts (both incomplete).
    1. I'm trying to come up with something that would search up, rather than down. Why? Well, if you have say a variable number of tabs in front of paragraph marks & you search for
    ^t{1,}^13 OR ^t@^13

    If you search up, using the first expression, you'll notice that the first expression will jump from paragraph to paragraph, and select all the trailing tabs. The second will jump from paragraph to paragraph, but select only one tab.
    Haven't thought this through yet.

    This MIGHT work
    2. Using one of the expressions that finds your line, do a ReplaceAll. Replace with itself (^&), but put a zero width space in front of it. After that, we can try to develop an expression that starts with a zero width space & ends with a number so that it won't select just parts of the address. Is this a possibility?

  10. #10
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcard Search (any)

    Phil,
    ReplaceAll would change the document. These are legal documents we're talking about. I'd rather just
    scrape the screen. The Find expression could be more exact if Word supported "zero or more" or "zero or
    one" occurence wildcards -- like regular expressions. Maybe a future version...

    Now, I see you are using and OR conditional. Do you know something I don't? You can't use that in an
    actual wildcard expression, can you? Or were you just showing me two different ways to approach your
    idea?

    Attached is a document that shows the various address blocks positioned as they may appear in one
    of our documents. My ExtractAddress method will find them all and display them in the Envelope dialog
    address textbox control. At this point I'm happy with collapsing the selection which prevents the method
    from finding the same address twice.
    Attached Files Attached Files
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  11. #11
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcard Search (any)

    Hi Kevin:
    I was using OR as an alternative in my post; i.e. two different expressions. I don't know any way to search for alternative expressions at once (you can search for alternative characters by putting them in brackets). Looking at your document, I can't see any common way to find each whole address block & not find partials. I don't see any unique pattern. If I come up with anything, I'll post back.

    Regarding the fact that they're legal documents, you'd just be adding a zero width space. You could always close the document without saving changes, but I assume that you're doing this with VBA & would rather not take chances.

Posting Permissions

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