Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #23  
Old 01-06-2025, 09:27 AM
gmaxey gmaxey is offline Regex-pattern Windows 10 Regex-pattern Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Quote:
Originally Posted by batman1 View Post
That's right. For example, can you provide a simple pattern in Word Find with the following task: "Find in the sequence all numbers consisting of 4 or 5 digits, whose first 4 digits must have at least 1 digit 2"

batman1,


I suppose the skills that someone is familiar with has bearing on what is simple or not. A simple find pattern? No, and one may not exists. However, with VBA your task is easy enough:



Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = "[0-9]{1,}"
    .MatchWildcards = True
    While .Execute
      Select Case Len(oRng.Text)
        Case 4
          If InStr(oRng.Text, "2") > 0 Then Debug.Print oRng.Text
        Case 5
          If InStr(Left(oRng.Text, 4), "2") > 0 Then Debug.Print oRng.Text
      End Select
    Wend
  End With
lbl_Exit:
  Exit Sub
End Sub
Sample Numbers:
12345 – Match
56789 – No Match
123 – No Match
1234 – Match
4321 – Match
8945 – No Match
98765 – No Match
124567 – No match
54312 – No match
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex-pattern Capture group in RegEx alex100 Word VBA 1 01-02-2021 02:39 PM
Regex-pattern Regex over 700 matches in a long doc totoMSOF Word VBA 19 03-11-2019 01:28 PM
Regex-pattern Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed abdan Word VBA 3 01-18-2019 09:38 PM
Macro help regex subspace3 Word VBA 1 10-15-2014 09:53 AM
Regex in Word: Replaced strings are in disorder chgeiselmann Word 0 04-26-2009 11:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:59 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft