Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-05-2017, 02:11 PM
noname91 noname91 is offline Renaming several strings of text by their pattern Windows 7 64bit Renaming several strings of text by their pattern Office 2007
Novice
Renaming several strings of text by their pattern
 
Join Date: Jan 2017
Posts: 6
noname91 is on a distinguished road
Question Renaming several strings of text by their pattern

Hello to all.



I'd like to ask if Word 2007 (or any application you might be aware of) has a feature which will allow me to rename a string within a text file. For example, I have the following:

global.test_1 = 1\2\3\sample_1.xxx
global.test_2 = 1\2\3\sample_2.xxx
global.test_3 = 1\2\3\sample_3.xxx

which I'd like to rename as:

FTEST(global.test_1)
FTEST(global.test_2)
FTEST(global.test_3)

Note that there are a couple hundred of such items that I'd like to rename. How would I go about doing so without extensive copy-pasting? I've tried googling for the solution but have been unsuccessful thus far.

Thank you for any help.
Reply With Quote
  #2  
Old 01-05-2017, 02:30 PM
macropod's Avatar
macropod macropod is offline Renaming several strings of text by their pattern Windows 7 64bit Renaming several strings of text by their pattern Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could do this with a wildcard Find/Replace, where:
Find = (global.test_[0-9]{1,})*^13
Replace = FTEST(\1)^p
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-05-2017, 03:05 PM
noname91 noname91 is offline Renaming several strings of text by their pattern Windows 7 64bit Renaming several strings of text by their pattern Office 2007
Novice
Renaming several strings of text by their pattern
 
Join Date: Jan 2017
Posts: 6
noname91 is on a distinguished road
Default

Thank you for the quick reply macropod.

So I used the Find/Replace function (Ctrl+F), and in the Replace tab, did the following:

. In the Find What field: (global.test_[0-9]{1,})*^13
. Ticked the "Use wildcards" option under Search Options
. In the Replace With field: FTEST(\1)^p
. Clicked Replace All

Unfortunately, I get a message telling me that 0 replacements were made. Am I doing something wrong is there another way to do this?

Thanks!
Reply With Quote
  #4  
Old 01-05-2017, 03:29 PM
macropod's Avatar
macropod macropod is offline Renaming several strings of text by their pattern Windows 7 64bit Renaming several strings of text by their pattern Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

All I can go on is what you posted, which implies your document contains a series of paragraphs, worded along the lines of:

global.test_1 = 1\2\3\sample_1.xxx
global.test_2 = 1\2\3\sample_2.xxx
global.test_3 = 1\2\3\sample_3.xxx

If that is not the case - even if the capitalisation of global.test differs - nothing will be found.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 01-05-2017, 03:33 PM
noname91 noname91 is offline Renaming several strings of text by their pattern Windows 7 64bit Renaming several strings of text by their pattern Office 2007
Novice
Renaming several strings of text by their pattern
 
Join Date: Jan 2017
Posts: 6
noname91 is on a distinguished road
Default

Thank you for reply macropod.

I am currently testing to see if the function works (hence the test names). If I use a freshly opened document and copy paste those three lines and follow your procedure, I still get 0 replacements.
Reply With Quote
  #6  
Old 01-05-2017, 04:03 PM
macropod's Avatar
macropod macropod is offline Renaming several strings of text by their pattern Windows 7 64bit Renaming several strings of text by their pattern Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Without actually seeing the actual file you're working on, it can be difficult for anyone to diagnose the issue. Can you attach a file to a post with some representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 01-05-2017, 04:06 PM
noname91 noname91 is offline Renaming several strings of text by their pattern Windows 7 64bit Renaming several strings of text by their pattern Office 2007
Novice
Renaming several strings of text by their pattern
 
Join Date: Jan 2017
Posts: 6
noname91 is on a distinguished road
Default

Sure. The attachment should be there.

Thanks.
Attached Files
File Type: docx test replace.docx (9.8 KB, 16 views)
Reply With Quote
  #8  
Old 01-05-2017, 04:19 PM
macropod's Avatar
macropod macropod is offline Renaming several strings of text by their pattern Windows 7 64bit Renaming several strings of text by their pattern Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your document contains a mix of manual line breaks and paragraph breaks. Accordingly, the Find/Replace should have treated the content as a single match and have replaced the lot with:
FTEST(global.test_1)

For your attachment's content, you could use a wildcard Find/Replace, where:
Find = (global.test_[0-9]{1,})*([^13^l])
Replace = FTEST(\1)\2
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 01-05-2017, 04:49 PM
noname91 noname91 is offline Renaming several strings of text by their pattern Windows 7 64bit Renaming several strings of text by their pattern Office 2007
Novice
Renaming several strings of text by their pattern
 
Join Date: Jan 2017
Posts: 6
noname91 is on a distinguished road
Default

Thanks for the reply macropod.

I believe I did see all lines being replaced with FTEST(global.test_1). The breaks you're talking about must have been causing issues before.

For the attachment, the second command appears to have worked! However, the first string seems to not have changed. What I have now is:

global.test_1 = 1\2\3\sample_1.xxx
FTEST(global.test_2)
FTEST(global.test_3)

This was done in the attachment. Is there any reason why the first line remains unchanged?

Thanks.
Reply With Quote
  #10  
Old 01-05-2017, 05:08 PM
macropod's Avatar
macropod macropod is offline Renaming several strings of text by their pattern Windows 7 64bit Renaming several strings of text by their pattern Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by noname91 View Post
For the attachment, the second command appears to have worked! However, the first string seems to not have changed. What I have now is:

global.test_1 = 1\2\3\sample_1.xxx
FTEST(global.test_2)
FTEST(global.test_3)

This was done in the attachment. Is there any reason why the first line remains unchanged?
Probably because you had the insertion point somewhere within that line when you executed the Find/Replace.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 01-05-2017, 05:46 PM
noname91 noname91 is offline Renaming several strings of text by their pattern Windows 7 64bit Renaming several strings of text by their pattern Office 2007
Novice
Renaming several strings of text by their pattern
 
Join Date: Jan 2017
Posts: 6
noname91 is on a distinguished road
Default

Thank you macropod. It works as intended.

Additionally, instead of numbers [0-9], I tried testing with letters [a-z] and was glad to see it worked well on that front as well.

This has been quite useful so much thanks for all your help!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming several strings of text by their pattern Extract Data From Text file based on Pattern PRA007 Word VBA 13 11-01-2015 11:20 PM
how do I search the content of excel files for text strings soren Excel 2 03-19-2015 09:42 AM
Renaming several strings of text by their pattern VBA to copy bookmark-hyperlinks to plain text strings Marrick13 Word 2 04-29-2012 05:12 AM
Renaming slide titles ragzdaddy PowerPoint 0 12-26-2011 01:18 PM
Renaming several strings of text by their pattern update style of all strings available between two specific strings vikrantkale Word 1 03-28-2011 06:13 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:50 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft