Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 01-28-2016, 09:46 AM
Marrick13 Marrick13 is offline Windows XP Office 2010 32bit
Advanced Beginner
 
Join Date: Jun 2006
Posts: 91
Marrick13 will become famous soon enough
Default Regex/wildcard search for dates with 2-digit and 4-digit years

I have been working with the attached code to see if I can get it to search and format dates in Word. I am trying to get it to search for a variety of formats, and having some success with a wildcard search. But Im stuck on searching the format 9/25/2014.

The wildcard expression Im using for this, "([0-9]{1,2})(/)([0-9]{1,2})(/)([0-9]{2})", finds both dates with 2- and 4-digit years. The code highlights '9/25/20 and ignores the 14 (as it should because of the {2}), but I want to find a way to have it search ONLY for dates with 2-digit years, instead of reading only the first 2 digits of 4-digit years. Been trying other wildcard switches but nothing achieves this specific search.



Can I get some help? Code is in the attached.
Attached Files
File Type: txt Format_All_Dates.txt (771 Bytes, 1 views)
Reply With Quote
  #2  
Old 01-28-2016, 02:00 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,392
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Try using:
"<([0-9]{1,2})(/)([0-9]{1,2})(/)([0-9]{2})>"
The < and > characters tell Word the found characters must start and end a word, respectively. If you want to include both 2-digit and 4-digit years, use:
"<([0-9]{1,2})(/)([0-9]{1,2})(/)([0-9]{2,4})>"
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 01-29-2016, 07:04 AM
Marrick13 Marrick13 is offline Windows XP Office 2010 32bit
Advanced Beginner
 
Join Date: Jun 2006
Posts: 91
Marrick13 will become famous soon enough
Default

Thanks, Paul - that's the ticket. I saw some descriptions of the <> characters but didn't quite understand how they really worked. You've clarified it for me. Thank you!
Reply With Quote
Reply

Tags
date, regex, search and replace

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
A challenging digit by digit manipulation, rotate the digit in range of 0 to 9 laucn Excel Programming 14 05-17-2015 12:12 PM
Outlook export to a calendar csv file is transposing single digit starting dates sala-marie Excel 3 10-27-2013 09:32 PM
Recipient counter in Mail Merge Wizard displays only one digit in Word Liuneddu Word 1 08-13-2013 03:57 AM
Import contact from EXCEL to Outlook (no zero in left side digit) nmo111 Outlook 1 05-28-2010 11:00 AM
Dividing merge cell into ten equal rectangles for inputing Digit? aligahk06 Excel 0 05-12-2010 06:56 AM


All times are GMT -7. The time now is 10:31 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft