I am trying to search for any positive integer between 1 and 99 that is inside square brackets, like [1] or [24]. So basically every instance of: open square brackets, a number from 1 to 99, close square brackets. Or sometimes ranges / pairs of numbers like [26-29] or even [30,31]. I have to replace all the instances of square brackets with normal parentheses; e.g., [1] would be replaced with (1), [42] would be replaced with (42), etc.
I've looked at [1-9]{1,}
and [1-9]{1,99}
Plus I have to change every instance of I to We because I wrote a 30-page article and a colleague of mine suddenly joined to help out on the work, so...
Apparently according to this documentation, there is the following approach:
But somehow I cannot get round it. Any help is highly appreciated as I have to end it by today.
Note: Microsoft Word for Mac Version 15.12.3
Go into “Find and Replace”, click on “More > >”, and click “Use wildcards”.
(But you already knew that, right?)
To search, literally, for a character that has special meaning in the wildcard (pattern matching) syntax, precede it with backslash (\
). So, to search for (literal) square brackets in the text, use \[
and \]
.
Zero is a valid digit, so you must use [0-9]
instead of [1-9]
.
[0-9]
might match numbers in those foreign alphabets. (Or maybe even letters and other symbols in those foreign alphabets.) It might be safer to use [0123456789]
.So, to match any whole number (non-negative integer), use [0-9]{1,}
or [0-9]@
.
To match any integer between 0 and 99, use [0-9]{1,2}
.
0
. If not matching 0
is important to you, say so.01
, 02
, 03
, ... 09
). And, for that matter, 00
. Again, say whether this is a serious problem.Use parentheses ( (
…)
) to delimit capture groups or expressions.
So, a simple search for a one- or two-digit number in square brackets, use \[[0-9]{1,2}\]
.
But, if you want to do a Find and Replace, and replace [42]
with (42)
, then find \[([0-9]{1,2})\]
and replace with (\1)
. This is a little confusing. In the “Find what” string (expanded for clarity):
\[ ( [0-9]{1,2} ) \]
↑ ↑
the parentheses (highlighted) delimit a capture group. In the “Replace with” string:
( \1 )
the parentheses are the literal parentheses characters that you want to insert, and \1
says “take what the first capture group matched (i.e., the number, without the brackets), and insert it here”.
To do the same thing with ranges of numbers, just find \[[0-9]{1,2}-[0-9]{1,2}\]
(and, again, replace with (\1)
. Ditto for comma-separated pairs of numbers: \[[0-9]{1,2},[0-9]{1,2}\]
.
Jack loves cats.
and you “Find”
Jack loves (*s).
and “Replace with”
(But Jill hates \1.)
the result is
(But Jill hates cats.)
<I>
and Replace All with We
. And, unless your entire document is written in title case, do a second pass, searching for <We>
(title case), and replace with we
(lower case) wherever it’s not the first word of a sentence.
Practically, it may be less work to search for <I>
and Replace All with we
(lower case), and then do a second pass, searching for <we>
(lower case), and replacing with We
(title case) wherever it is the first word of a sentence. It might be possible to do this automatically with wildcards, along the lines of
^013we> ⇒ ^pWe
and
([.\!?] @)we> ⇒ \1We
but I haven’t tested this thoroughly.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments