Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Wildcards search excluding a specified character (Word97)

    Hi

    Using a Word wildcard search, is it possible to specify a find text that excludes any occurrence of a specified character?

    For example, let's say the document contains the following text: "XabcdXefghX", and I want to find all strings starting and ending with X, but not including b. Searching for "X*X" nearly does it, but finds "XabcdX" (which I don't want, because it contains a "b") as well as "XefghX".

    Can do?
    Dale

  2. #2
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcards search excluding a specified charact

    I don't have a copy of Word 97 handy, but here's the wildcard (make sure "use wildcards" is checked) pattern for what you want:
    <pre><X[!b]@X>
    </pre>


    "<X" is "match X at the beginning of a word
    [!b]@ is "one or more characters that aren't 'b'"
    "X>" is "match X at the end of the word

    HTH.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Wildcards search excluding a specified charact

    Thanks, Andrew. Quite powerful, isn't it. Reminds me of conversion mechanism that was used by Folio Views.

    Is it possible to exclude a string? For example, let's say the document contains the following text: "XyyybcyyyXyyycbyyyX", and I want to find all strings starting and ending with X, but not including the string "bc" (that is, I want to find "XyyycbyyyX", but not "XyyybcyyyX").

    Thanks for your help
    Dale

  4. #4
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcards search excluding a specified charact

    Hi Dale,

    Word's wildcards are more powerful than most people realize, but they're still rather limited. That kind of match is a bit more than it can handle on its own. The best you could probably do natively is to use some VBA to examine the matches to the original pattern to see if they include the substring, then act based on that.

    Complex pattern matching in strings is not an uncommon task, and there are many tools far better suited for it than Word. You're even further limited by still using Word 97. With Word 2000 and up, you have access to the VBScript RegExp object, which gives you access to a full Regular Expression (string-pattern matching) engine:
    http://www.windowsdevcenter.com/pub/a/wind...dex.html?page=4

    Generally, when complex patterns like this come up, I turn to other tools like Perl or Ruby:
    http://www.perl.com/pub/a/2005/05/26/word_control.html

Posting Permissions

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