Consulting

Results 1 to 3 of 3

Thread: Include underscores in found strings

  1. #1
    VBAX Regular
    Joined
    Mar 2022
    Posts
    7
    Location

    Include underscores in found strings

    Greetings,

    I'm looking for a way to include underscores in strings I look for with Find object.
    I have a data set of strings I'm looking for in a document. The strings may or may not include underscores, and the document may contain partials of that string, or more than the desired string.

    Examples: I want to find following strings "Word", "Word_A", "Word_B". The document may include strings that I do not want to edit such as "Word_ABC" or "Word_A_1".
    With MatchWholeWord it would find the "Word" in "Word_ABC" and "Word_A" in "Word_A_1" when those should be left unedited.

    The underscores can appear anywhere within the words except for the first character, so I can't filter them based on location of the character.

  2. #2
    For your examples, use a wildcard search for <Word_[AB]{1}>[!_]
    See https://www.gmayor.com/replace_using_wildcards.htm
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Mar 2022
    Posts
    7
    Location
    Hi, I figure my examples were a little poorly formed.

    The strings can be any set of numbers and letters with or without underscores. There also isn't any specific pattern that can be excluded (or included) by search. Words with underscore would fall under [0-9A-Z]_[0-9A-Z].
    Using the filter above would obviously ignore the strings that don't have underscores. I have reviewed the data and each string I want to find and edit, can only include 0-1 underscores. The problem forms when I want to find a string of only [0-9A-Z] and the document contains same string but longer divided by an underscore (such as my previous examples).

    Does this mean I should divide my data set into two parts where other has underscored strings and other doesn't? Then I could apply the underscore filter either between the [0-9A-Z]_[0-9A-Z] or to find words that do not have underscores at the end of the string.
    I will have dive deeper into wildcard search to better utilize it.

Tags for this Thread

Posting Permissions

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