View Single Post
 
Old 10-30-2021, 04:33 PM
Steve Kunkel Steve Kunkel is offline Windows 10 Office 2019
Advanced Beginner
 
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