#1
|
|||
|
|||
VBScript.RegExp: exclude a particular word
This is not just an Excel VBA question, anyway, I'd post it here for help:
Code:
Dim str6 As String str6 = "cat and dog" With CreateObject("VBScript.RegExp") .Global = True .IgnoreCase = True .Pattern = "\b[^cat]{3}\b" For Each oMatch In .Execute(str6) Debug.Print oMatch Next oMatch End With ''' output ''' dog Code:
.pattern = "[^cat]" Quote:
|
#2
|
||||
|
||||
Hi,
Here's one pattern (a negative lookahead) which will exclude dog: Code:
.Pattern = "(?!dog\b)\b\w+" |
#3
|
|||
|
|||
Quote:
But just wanna ask why \b after dog is needed? To state the pattern ends by "dog" before the word boundary "\b"? And the \b outside before \w is used for what? |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
.doc Suddenly Changed to .vbe (VBScript Encoded Script File) | emes | Word | 2 | 04-24-2012 05:07 PM |
WORD: Rtf and search-replace (regexp/fonts) | seteshpl | Word | 1 | 09-06-2011 01:35 AM |
Edit spell check dic to exclude words? | franklekens | Word | 1 | 07-03-2010 09:57 AM |
VbScript to Print a .pdf | DaveB | Excel | 2 | 03-07-2009 12:36 PM |