3

The issue that I am running into is that while the "Find" bar can 'read' wildcards, the "Replace" bar seemingly cannot, even when I click "Use Wildcards" while in the "Replace" bar. I am on a Windows computer, and I believe I have the newest version of Word.

I am trying to replace instances like the following: "word 123" => "word, 123"

My setup in the "Find and Replace" window was as follows (with "Use Wildcards" turned on, of course):

  • FIND: [a-z] [0-9]
  • REPLACE: [a-z], [0-9]

This did the trick for finding all instances. But when I clicked "Replace", instead of creating "word, 123", it would remove the "d" and "1" and literally insert the "Replace" command, creating "wor[a-z], [0-9]23".

I do understand why it is replacing the "d" and "1" and inserting the command, I am just looking to figure out how to do the replacement properly -- leaving the string as it was and simply inserting the comma after the letter.

I have seen threads with the commands to replace the first or second group in a wildcard (/1 or /2), but would those work in this situation, since what I would like to replace is between the "letters" and "numbers" groups?

This is a recurring edit that comes up in my job, so this would be incredibly helpful going forward. Thank you!

New contributor
Alex Mathews is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
6
  • 1
    first it looks like you are trying to use regular expressions instead of wildcards. the most common wildcard in windows is * meaning "any character for any length". second you are attempting to use a regex as your replace expression as well. in a find/replace feature that will use regex, the replace expression should take the form of capture groups and literal text. it should never be another regex, since its replacing, not matching. wildcards do not equal regex patterns in all applications (or really even most). Commented yesterday
  • Hi @FrankThomas , this is very informative, but I am not sure how to fix the issue based on this answer. What would be the correct way to fill out the Find and Replace in my case? (Additionally, the [a-z] and [0-9] do appear to be wildcard operators as well as regex according to the top response on this post: superuser.com/questions/86397/wildcards-in-word, in case that makes a difference in the solution) Commented yesterday
  • It does appear that winword supports some degree of regex search, so as a first try I'd probably make the search expression "{[a-z]} {[0-9])" (the parentheses create capture groups), and the replace statement like "$1, $2" meaning "group1, a comma, a space, and then group2". the exact dialect of regex you need to use is application specific, but you may want to start with this: software-solutions-online.com/vba-regex-guide Commented yesterday
  • ok from your link, the replace would probably be "\1, \2" instead of dollar signs. it varies between dialects. Commented yesterday
  • @FrankThomas Word doesn’t support regex through the GUI – only its own half-useless type of ‘wildcards’ (which is a mixture of actual wildcard characters and dumbed-down regular-ish expressions). More advanced regex requires a script/macro, where you can leverage VBA regex (as described in your link), but this is almost certainly quite far beyond the abilities of a regular user. Commented 17 hours ago

1 Answer 1

6

You can use kind of regex in Word. Search for:

([a-zA-Z]) ([0-9]) 

and replace it with:

\1, \2 

The items, defined in brackets () define groups which in replace are represented with \1, \2...

You should have marked "Use wildcards"

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.