#1
|
|||
|
|||
"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" 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" |
#2
|
||||
|
||||
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 |
#3
|
|||
|
|||
Excellent resources. Thanks Gmayor!
|
|
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 |
Rebinding "Ctrl+F" to bring up Find & Replace Window in Word 2013 | ravl13 | Word | 4 | 12-09-2016 02:58 PM |
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 |
Find & Replace words with "/" prefix & suffix | tollanarama | Word | 4 | 01-25-2011 02:19 AM |