Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-03-2022, 03:02 PM
BrianHoard BrianHoard is offline How to remove square brackets surrounding numbers with commas Windows 10 How to remove square brackets surrounding numbers with commas Office 2019
Advanced Beginner
How to remove square brackets surrounding numbers with commas
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default How to remove square brackets surrounding numbers with commas

We have built a script to remove square brackets surrounding numbers, like [2] or [99999], then making the numbers formerly wrapped in square brackets to superscript.

But today, we found we also must remove square brackets from comma-separated numbers, like [2,3] or [2,3,4,5,6,7,8,9,10]

I'm trying to do wildcards in find, like this, but this only works for patterns with a single comma.

In my .Find.Text attempt, here's what I'm trying to do...
- Find a literal open square bracket,
- followed by any number, 1 or more times,
- group start
- followed by a literal comma, 0 or one times,
- followed by any number 1 or more times


- group end
- the above group 0 or more times,
- ending with a close square bracket]

Code:
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Format = False
    .Forward = True
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Text = "\[[0-9]{1,0}(\,[0-9]{1,0}){,}\]"
    .Replacement.Text = ""
  End With

  Do While .Find.Execute = True
    str_found = .Text
    str_found = Replace(str_found, "[", "") ' replace open [ bracket with nothing.
    str_found = Replace(str_found, "]", "") 'replace close ] bracket with nothing
    .Font.Superscript = str_found
    .Text = str_found ' Replace the text in doc, now without square [] brackets.
    .Collapse wdCollapseEnd
  Loop
End With
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to remove square brackets surrounding numbers with commas Need Wild Card for Deleting Square Brackets with Differing Numbers inside CrossReach Word 6 11-26-2019 01:02 PM
What are the areas in square brackets [ ]? mummy Word 3 01-24-2018 05:15 AM
How to remove square brackets surrounding numbers with commas Bold numbers between square brackets jeffreybrown Word 4 02-13-2017 04:32 PM
How to remove square brackets surrounding numbers with commas Help with: Replace and reformat numbers inside square brackets johnbrowny Word 1 02-13-2016 06:45 PM
Gray square brackets waldux Word 8 09-25-2013 04:14 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:48 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