Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pattern Match / Regex with Find in Word 1

Status
Not open for further replies.

utoyo

Technical User
Mar 5, 2005
123
US
I often have to relabel sets of numbers in word. For example, 200, 201, 202, 203 needs to be changed to 300, 301, 302, 303. I can use find and replace but that is tedious.

Can I use Word's find function to find and replace all 2## occurrences? (The real problem is avoid replacing 2 with 3 where I have a number like 222 or 202 which would become 333 and 303 instead of 322 and 302.)

Thanks in Advance.
 
I'm not 100% sure what you want but try:

Find [blue][tt]2([0-9][0-9])[/blue][/tt]
Replace with [blue][tt]3\1[/blue][/tt]
Check "Use wildcards"

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Sorry about the formatting - let's try again:

Find [blue][tt]2([0-9][0-9])[/tt][/blue]
Replace with [blue][tt]3\1[/tt][/blue]
Check "Use wildcards"

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Tony thanks so much that works great! Is the \1 after the 3 so that it only changes one 3 per match?

 
No the \1 is the first (number 1) 'group' (parenthesised expression) in the Find what text - in this case the two digits after the initial 2.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
How would I change the middle number in a set of numbers? For example, if I have 202, 204, 206 and I want to make them 292, 294, and 296.

I've tried:
Find: ([0-9])0([0-9])
Replace: 9/2

Also, tried 9/1 but both just change things to 9#, i.e. 202 becomes 92.
 
The Find is good - and you're almost there with the replace.

Replace with <group 1>9<group 2> - or [red]\1[/red]9\2

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top