3

Been poking around the internet but I can't seem to find one. This would be nice for cases such as finding and replacing numbers, i.e. one|1. I'd want to replace with one (1).

A. Eakins
  • 303
  • 1
  • 2
  • 14
  • Don't try to use RegEx inside a Word document. RegEx can only work on a string, divorced from the document content. Word's built-in Find and wildcards are needed. And, no, there is no "OR" functionality. – Cindy Meister Mar 09 '20 at 20:32
  • 2
    I was under the impression that these wildcards were a flavor of Regex, so that's what I meant when I said RegEx - the wild cards. And what exactly is a string "divorced from document content". The document content is literally a series of strings; do you mean divorced from formatting markup? That's unhelpful. But you're right. I did some more research. There is no OR operator. – A. Eakins Mar 10 '20 at 20:18
  • «The document content is literally a series of strings». Not so. A Word document is far more than just a 'series of strings'. Word documents typically contain tables, fields (e.g. cross-references, hyperlinks), automatic numbering & bullets, footnotes/endnotes, images, etc., etc., none of which RegEx plays well with. – macropod Mar 11 '20 at 10:42
  • Should be closed as a duplicate of https://stackoverflow.com/questions/34206312/wildcard-mask-or-operator-is-not-working/34225751#34225751 – Cindy Meister Mar 11 '20 at 11:06
  • 1
    When discussing software, terminology is very important. RegEx is something; Word's wildcards are something else. When the term RegEx is used it's interpreted literally by those reading. So it's very important to use the correct terminology... – Cindy Meister Mar 11 '20 at 11:08
  • You're right. But most of the content is strings, which means most of the content would work well with Regex. The only content I'd be interested in changing is the strings. And Word's Wildcards are fairly commonly called RegEx in any case: https://www3.ntu.edu.sg/home/ehchua/programming/howto/PowerUser_MSOffice.html. That's just one of many links. I understand they are different. I understand the implementation is different. And in any event, VBA supports RegEx as well, not just Word's brand of wildcards. RegEx works well with strings. Let's assume I want to use it (OR WILDCARD) for a reason. – A. Eakins Mar 11 '20 at 13:55

1 Answers1

4

As Cindy pointed out, there is no "OR" operator using wildcards: https://answers.microsoft.com/en-us/msoffice/forum/all/or-operator-in-word-find/c7342d5e-9e08-43f2-96c5-347050601b01. That said, if you were to use Visual Basic to write a macro, you could "import" a RegEx object and use that, which SHOULD allow you to use an OR operator such as: "|" How to Use/Enable (RegExp object) Regular Expression using VBA (MACRO) in word. That's more difficult to build out than a simple Find and Replace. The operator in that case is, in fact "|", according to this document: https://www.udemy.com/blog/vba-regex/. But RegEx has many different implementations, or flavors, it's not a universal standard, even if many implementations share syntax. See this: https://en.wikipedia.org/wiki/Comparison_of_regular-expression_engines. This COULD have been different. And Word's wildcards, even if they're not traditional RegEx (I initially thought they were a flavor of RegEx but no longer do), could have supported an OR operator. They just don't as of this writing.

A. Eakins
  • 303
  • 1
  • 2
  • 14