Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-30-2021, 04:33 PM
Steve Kunkel Steve Kunkel is offline "Alternation" with Find-n-Replace wildcards? Windows 10 "Alternation" with Find-n-Replace wildcards? Office 2019
Advanced Beginner
"Alternation" with Find-n-Replace wildcards?
 
Join Date: May 2019
Location: Seattle area
Posts: 81
Steve Kunkel is on a distinguished road
Default "Alternation" with Find-n-Replace wildcards?

Do you guys know if this is possible? I'm using VBA, though I guess this isn't a VBA question, per se. The top three are working regular expression setups from another project. I'd like to recreate those in my Word VBA project.



With the bottom three, the first two are working setups, but the very bottom one doesn't work because "(s|z|sh|ch|x|o)" seems to match any single character in the range.

I think what I'm looking for is called "alternation?"

For example I'd like this "xxx(s|z|sh|ch|x|o)es" to match
xxxches
xxxshes

but not match
xxxces

Is this possible?


PERL regular expression.
Code:
Find "s)([Tt]hey\s)(.*?)ies\b" and Replace with "$1$2y"
Find  "s)([Tt]hey\s)(.*?)s\b" and Replace with  "$1$2" 
Find  "s)([Tt]hey\s)(.*?)((s|z|sh|ch|x|o))es\b" and Replace with "$1$2$3"
Word Wildcards
Code:
Find "([Tt]hey )([a-z]@)ies" and Replace with  "\1\2y"
Find  "([Tt]hey )([a-z]@)s"  and Replace with  "\1\2"
Find  "([Tt]hey )([a-z]@(s|z|sh|ch|x|o))es"  and Replace with  "\1\2"
Reply With Quote
  #2  
Old 10-31-2021, 03:33 AM
gmayor's Avatar
gmayor gmayor is offline "Alternation" with Find-n-Replace wildcards? Windows 10 "Alternation" with Find-n-Replace wildcards? Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You can't do this in one pass with VBA - see Replace using wildcards. You can however use regular expressions in VBA - see The Complete Guide to Regex in VBA - VBA and VB.Net Tutorials, Education and Programming Services
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 10-31-2021, 06:41 AM
Steve Kunkel Steve Kunkel is offline "Alternation" with Find-n-Replace wildcards? Windows 10 "Alternation" with Find-n-Replace wildcards? Office 2019
Advanced Beginner
"Alternation" with Find-n-Replace wildcards?
 
Join Date: May 2019
Location: Seattle area
Posts: 81
Steve Kunkel is on a distinguished road
Default

Excellent resources. Thanks Gmayor!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Find and Replace" tool leaves out many of the occurrences of what I put in the "find" window Swarup Word 8 06-24-2021 08:31 PM
"Alternation" with Find-n-Replace wildcards? Rebinding "Ctrl+F" to bring up Find & Replace Window in Word 2013 ravl13 Word 4 12-09-2016 02:58 PM
"Alternation" with Find-n-Replace wildcards? Is there a way to use "find/replace" to find italics words? slayda Word 3 09-14-2011 02:16 PM
"Find" Wildcards djreyrey Word 2 03-20-2011 09:36 PM
"Alternation" with Find-n-Replace wildcards? Find & Replace words with "/" prefix & suffix tollanarama Word 4 01-25-2011 02:19 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:42 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft