![]() |
#1
|
|||
|
|||
![]() Code:
Sub test() Dim str As String str = "str 9999 9999 str" Dim RegExp As Object Set RegExp = CreateObject("vbscript.regexp") With RegExp .IgnoreCase = True .MultiLine = False .Pattern = "[!0-9]" .Global = True End With output = RegExp.Replace(str, "") MsgBox output Set RegExp = Nothing End Sub |
#2
|
||||
|
||||
![]()
I think you mean to use this:
Code:
.Pattern = "[^0-9]" Code:
.Pattern = "\D" |
#3
|
|||
|
|||
![]()
Exactly. Thanks for reminding me about the use of "\D".
Just wonder why the tutorial below says this: http://www.gmayor.com/replace_using_wildcards.htm Under the "[!]" section, it says "!" means "NOT". Does VBA regular expressions share a different set of symbols from "Find and Replace" regular expressions? |
#4
|
||||
|
||||
![]()
Hi,
That find and replace tutorial is for using Microsoft Word's find and replace tool. Regex has it's own set of wildcards and special characters, examples: http://www.aivosto.com/vbtips/regex.html |
#5
|
|||
|
|||
![]()
Thank you for the reference.
It adds more to my programming library... |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
user0044 | Project | 5 | 03-06-2012 07:28 AM |
![]() |
sesproul | Mail Merge | 1 | 11-30-2011 05:02 AM |
![]() |
ZLA | Office | 3 | 07-23-2010 10:00 AM |
Issue skipping characters by Regular Expressions in Word | pochtara | Word VBA | 0 | 04-01-2010 05:37 AM |
How do I have headers and footers appear as regular text for the whole document? | user908045 | Word | 0 | 03-13-2010 12:41 PM |