How to replace every occurrence of [1]-[99] in Microsoft Word 2015?

Ava Barbilla

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:

  • <, >: Positional Anchors

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

G-Man Says 'Reinstate Monica'
  • 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].

    • If you have languages other than English in your document, and particularly if you have alphabets other than the Roman alphabet (e.g., Arabic or Chinese), [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}.

    • This will match 0.  If not matching 0 is important to you, say so.
    • This will also match two-digit numbers with a leading zero (i.e., 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}\]


    To give another example of parentheses in Find and Replace (one that is, hopefully, clearer), suppose you have the text

    Jack loves cats.
    

    and you “Find”

    Jack loves (*s).
    

    and “Replace with”

    (But Jill hates \1.)
    

    the result is

    (But Jill hates cats.)
    

As to the second part of the question: to change every instance of I to We, search for <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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to replace every second occurrence of a word in a string

From Java

How can I replace the first occurrence of a character in every word?

From Dev

How can I replace the first occurrence of a character in every word?

From Dev

Replace every occurrence of a word with a new HTML content

From Dev

Regular expression to replace nth occurrence of a word on every line in Textpad

From Dev

Replace every occurrence of a word with each line from an list-file

From Dev

Regular expression to replace nth occurrence of a word on every line in Textpad

From Dev

Check $1 with sed to conditionally replace last occurrence of a word in a path string

From Java

How can I replace every occurrence of a String in a file with PowerShell?

From Dev

How to use sed to replace every occurrence of a pattern minus one case?

From Dev

How to replace every nth occurrence of pattern using sed ONLY

From Dev

Replace every odd occurrence of space with “_”

From Dev

Replace every odd occurrence of space with “_”

From Dev

How to replace word occurrence in ranges specified using sed command?

From Dev

Replace last occurrence word in javascript

From Dev

replace only first occurrence of a word

From Dev

How to select every table in a Microsoft Word document using VBA Macro

From Dev

Replace every nth Occurrence in a Perl Script

From Dev

regex replace only the first occurrence of every match

From Dev

Regex - replace every odd/even occurrence

From Dev

regex replace only the first occurrence of every match

From Dev

Python replace every odd occurrence of space with "_"

From Dev

Replace every nth character occurrence in Java

From Dev

How to replace every comma with a new word from a file

From Dev

How to replace every 2nd specific word in a list

From Dev

Replace n-th occurrence of a word

From Dev

Using sed to replace nth occurrence of a word

From Dev

In Notepad++ , how to replace with new line, every last occurrence of a pattern in a line?

From Dev

How do I find and replace 'whole words only', in Microsoft Word?

Related Related

  1. 1

    How to replace every second occurrence of a word in a string

  2. 2

    How can I replace the first occurrence of a character in every word?

  3. 3

    How can I replace the first occurrence of a character in every word?

  4. 4

    Replace every occurrence of a word with a new HTML content

  5. 5

    Regular expression to replace nth occurrence of a word on every line in Textpad

  6. 6

    Replace every occurrence of a word with each line from an list-file

  7. 7

    Regular expression to replace nth occurrence of a word on every line in Textpad

  8. 8

    Check $1 with sed to conditionally replace last occurrence of a word in a path string

  9. 9

    How can I replace every occurrence of a String in a file with PowerShell?

  10. 10

    How to use sed to replace every occurrence of a pattern minus one case?

  11. 11

    How to replace every nth occurrence of pattern using sed ONLY

  12. 12

    Replace every odd occurrence of space with “_”

  13. 13

    Replace every odd occurrence of space with “_”

  14. 14

    How to replace word occurrence in ranges specified using sed command?

  15. 15

    Replace last occurrence word in javascript

  16. 16

    replace only first occurrence of a word

  17. 17

    How to select every table in a Microsoft Word document using VBA Macro

  18. 18

    Replace every nth Occurrence in a Perl Script

  19. 19

    regex replace only the first occurrence of every match

  20. 20

    Regex - replace every odd/even occurrence

  21. 21

    regex replace only the first occurrence of every match

  22. 22

    Python replace every odd occurrence of space with "_"

  23. 23

    Replace every nth character occurrence in Java

  24. 24

    How to replace every comma with a new word from a file

  25. 25

    How to replace every 2nd specific word in a list

  26. 26

    Replace n-th occurrence of a word

  27. 27

    Using sed to replace nth occurrence of a word

  28. 28

    In Notepad++ , how to replace with new line, every last occurrence of a pattern in a line?

  29. 29

    How do I find and replace 'whole words only', in Microsoft Word?

HotTag

Archive