In the comments on my post on using wildcards to replace and reformat text inside square brackets, Simon J asked what he’d need to use to find all numbers inside brackets.
I can think of a scenario where I’d want to do what Simon is asking—some of my authors, usually from an engineering background, will write out a number in full then put the numeral in brackets after the word (e.g. seventeen (17) joists, five (5) days). I usually delete one of these when I’m editing, as there’s typically no reason to have both.
Find what field:
- To find numbers inside square brackets, make sure Use wildcards is on, then type this in the Find what field: \[[0-9]{1,10}\]
- To find numbers inside parentheses (round brackets), make sure Use wildcards is on, then type this in the Find what field: \([0-9]{1,10}\)
Replace with field:
- To replace what you found with nothing (i.e. delete all such occurrences), then leave the Replace field empty. Note: You may end up with double spaces (the spaces either side of the deleted bracketed number string), so do a standard find and replace to replace them with a single space.
- To replace what you found with something else, then add that to the Replace field.
Notes and warnings:
- This method only finds WHOLE numbers. Numbers with anything else in them (letters or any sort of punctuation, such as decimal points, any sort of hyphen or dash, commas as thousand separators, percent symbols etc.) will NOT be found.
- You can change the parameters of the search string—the example above looks for one to ten consecutive numerals inside the brackets (this is the {1,10} bit). If you wanted different parameters, then you can change these values. For example, {2,5} would look for any whole numbers with 2, 3, 4, or 5 numerals (it would ignore single numbers and numbers with 6 or more numerals), and {1,} would look for numbers of any length from single-digit numbers through to an unlimited string of numbers.
- This method does not allow you to replace just parts of the found string with other characters. For that you would need to surround each element in parentheses. For the first example, you’d use (\[)([0-9]{1,10})(\]), and for the second you’d normally use ([\(])([0-9]{1,10})([\)]), (Hint: Copy this string—there are lot of punctuation marks in here that you could get wrong if you try to type is out).
[Links last checked January 2020]