MS Word - how to replace numbers with themselves, but bold?
Thread poster: LEXpert

LEXpert  Identity Verified
United States
Local time: 07:34
Member (2008)
Croatian to English
+ ...
Mar 24, 2013

In MS Word (Office 2007), I would like to search for all one- and two-digit numbers in a section of the text and replace the numbers with same numbers, but bolded. I can search for single digits (use wildcards, find: [1-9]), and this finds the numbers (finding just single digits will work Ok in this situation). However, I can't figure out what the Replace string should be. Applying a bold attribute to the replacement string is easy enough, but what is the actual replacement string? Replace: [1-9] will simply insert "[1-9]", so that's not it. Any ideas?
TIA,
Rudi


 

Ambrose Li  Identity Verified
Canada
Local time: 08:34
Chinese to English
+ ...
Possibly... Mar 24, 2013

Regular expression syntax in all text editors should be roughly similar, so the answer probably involves some variation of possibly-backslash-escaped parentheses (the grouping operator), and \1 (backreferences).

According to http://office.microsoft.com/en-us/word-help/find-and-replace-text-by-using-regular-expressions-advanced-HA102350661.aspx this should do the trick. (I don’t have Word to test whether this actually works or not.)

Search string: (<[1-9][0-9]?>)

This should match 1–9 optionally followed by 0–9, preceded by the beginning of a word boundary, and followed by a word boundary. The parentheses make it possble to reference the match in the replace string.

Replace string: Just use \1 to represent whatever is matched.

[Edited at 2013-03-24 03:45 GMT]


 

wotswot  Identity Verified
France
Local time: 14:34
Member (2011)
French to English
Search for 1 and 2-digit numbers Mar 24, 2013

The correct pattern-matching syntax in Word is:

([0-9]{1,2}) (in English-language editions of Word), or
([0-9]{1;2}) (in French-language editions of Word, which use the semi-colon instead of the comma between the curly brackets (enumerator clause)).
(Term conventions: [] = square brackets, () = round brackets, {} = curly brackets)

Incidentally, I always use [0-9] instead of [1-9] because French numbers under 10 (dates in particular) often include the leading 0 (zero). One "gotcha" I sometimes encounter: some people use the capital O (the letter between N and P!) instead of the 0 (zero)! Go figure!

I should just point out that Word's pattern-matching (aka wildcard) syntax is not strictly speaking Regex (regular expression) syntax, merely a simplified (more user-friendly) subset thereof.

In Replace, just enter \1 and set it to Bold.


 

LEXpert  Identity Verified
United States
Local time: 07:34
Member (2008)
Croatian to English
+ ...
TOPIC STARTER
@Wotswot - perfect, thanks! Mar 24, 2013

Wotswot's solution worked perfectly.
Thanks to you and Ambrose for your efforts. Much appreciated!


 

Ambrose Li  Identity Verified
Canada
Local time: 08:34
Chinese to English
+ ...
Regex Mar 24, 2013

wotswot wrote:

I should just point out that Word's pattern-matching (aka wildcard) syntax is not strictly speaking Regex (regular expression) syntax, merely a simplified (more user-friendly) subset thereof.


Technically speaking, for a notation to be regex, all it has to support is *, ?, alternation, grouping, and some way to specify a set of characters to match. All other things can be derived from these and are merely notational conveniences.

But of course, if we take such a basic definition of regex to go with then we don’t even have backreferences (which are vital for find-and-replace). So I guess it depends on what we mean by “regex.”

PS: Sorry for the incessant edits.

[Edited at 2013-03-24 20:08 GMT]


 

trhanslator (X)
Matches three-number digits too ... Mar 25, 2013


([0-9]{1,2})


Matches 123, 456 and 789 too.


 

Ambrose Li  Identity Verified
Canada
Local time: 08:34
Chinese to English
+ ...
word boundaries Mar 25, 2013

trhanslator wrote:


([0-9]{1,2})


Matches 123, 456 and 789 too.


That’s quite expected. That’s why you need the < and > to delimit the beginning-of- and end-of-word boundaries…


 


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

MS Word - how to replace numbers with themselves, but bold?

Advanced search






Déjà Vu X3
Try it, Love it

Find out why Déjà Vu is today the most flexible, customizable and user-friendly tool on the market. See the brand new features in action: *Completely redesigned user interface *Live Preview *Inline spell checking *Inline

More info »
PerfectIt consistency checker
Faster Checking, Greater Accuracy

PerfectIt helps deliver error-free documents. It improves consistency, ensures quality and helps to enforce style guides. It’s a powerful tool for pro users, and comes with the assurance of a 30-day money back guarantee.

More info »



Forums
  • All of ProZ.com
  • Term search
  • Jobs
  • Forums
  • Multiple search