Power Tip: Using variables to Search and Replace in Word

Page 2 of 3 (45 items) < Previous 1 2 3 Next >
This post has 44 Replies | 5 Followers

Posts 1507
Forum MVP
Fr Devin Roza | Forum Activity | Replied: Wed, Jun 27 2012 11:49 PM

fgh:

My guess, from the languages you've mentioned and my own experience of which [British] English books I've found it in, would be that it's originally a Catholic thing. I don't think I've ever seen it in Swedish.

I've also seen in an article or two the comma format referred to as typical in Catholic writings. Interestingly, the (Catholic) New American Bible notes in English use the comma system, I believe, another indication along those lines.

fgh:

With "complicated" I was more referring to something like "8:4-6,11,14; 17; 21:12f,16; 23". Before you replace commas with colons you have to make sure that the book doesn't already use colons for something else, or you'll end up with a string where you can no longer figure out what's supposed to be a verse and what's supposed to be a chapter.

Good point. If the author does not put a space after the comma when doing citations like 8:4-6,11,14 then that would in fact cause problems. If he puts a space after the comma in those cases it would work correctly.

Posts 1507
Forum MVP
Fr Devin Roza | Forum Activity | Replied: Wed, Jun 27 2012 11:52 PM

Keep Smiling 4 Jesus :):

Should have used wildcard search string:

(??bible-on[\}]{2})(??[\@]BibleKJV:[0-9,A-Z]{1,2}[a-z]{1,2}[0-9]{1,3})(:1)([\]]{2})

with replacement

\2\4 \1\2\3\4

Now that, my friends, is a search and replace string! Thanks for sharing KS4J!

Posts 1394
James Taylor | Forum Activity | Replied: Sun, Apr 17 2016 4:33 AM

Fr Devin Roza:
This technique can also be used to insert the codes which Personal Books need to indicate that a certain heading is, for example, a Dictionary Head Word. If all the head words in your dictionary have the same formatting, in just a matter of a few minutes of work you could apply the information that the Logos Personal Book needs to recognize 1000s of head words.

Have you actually done this Fr Devin Roza? If so, Could you please post a screen shot of the find and replace window as you did for the above example?

Logos 8  | Dell Inspiron 7373 | Windows 10 Pro 64, i7, 16GB, SSD | iPhone X | iMac 27" i7, 16GB, SSD | OS 10.13

Posts 1507
Forum MVP
Fr Devin Roza | Forum Activity | Replied: Sun, Apr 17 2016 8:38 AM

James Taylor:

Fr Devin Roza:
This technique can also be used to insert the codes which Personal Books need to indicate that a certain heading is, for example, a Dictionary Head Word. If all the head words in your dictionary have the same formatting, in just a matter of a few minutes of work you could apply the information that the Logos Personal Book needs to recognize 1000s of head words.

Have you actually done this Fr Devin Roza? If so, Could you please post a screen shot of the find and replace window as you did for the above example?

I hadn't done it, but I did right now. Here are some test files, and the search. In the test file, the headwords we want to mark up are using Heading 1, which is what I will be replacing with the text Logos/Verbum needs to tell it this is an Encyclopedia headword. When you import the book, be sure to classify it as an encyclopedia.

Original Dictionary file: 5822.Test.docx

Dictionary file ready for Logos/Verbum: 6036.TestResult.docx

Here is the search you need to run to get from the original to the final file. Just click Replace All, and it will do all of them at once:

A few notes about this search:

- The search is for text that is Heading 1, any number of characters or words long, until it hits a carriage return (^13).

- The replace text uses \1 to indicate the variable (everything in between the () in the search string). Note that the replace string uses ^p instead of ^13. This is important, as ^13 does not work correctly in the replace string to indicate a carriage return (^13 doesn't work properly with styles in the replace box). 

Posts 1394
James Taylor | Forum Activity | Replied: Sun, Apr 17 2016 9:29 AM

Thank you so much for taking the time to share this! This is a game changer. I have many old dictionaries, encyclopedias that will now have headword milestones :-) You are a blessing

Logos 8  | Dell Inspiron 7373 | Windows 10 Pro 64, i7, 16GB, SSD | iPhone X | iMac 27" i7, 16GB, SSD | OS 10.13

Posts 1394
James Taylor | Forum Activity | Replied: Sun, Apr 17 2016 12:40 PM

Just did an encyclopedia, 540 Headwords coded in 1 sec. I'm suffering from perma-grin right now Big Smile

Logos 8  | Dell Inspiron 7373 | Windows 10 Pro 64, i7, 16GB, SSD | iPhone X | iMac 27" i7, 16GB, SSD | OS 10.13

Posts 1507
Forum MVP
Fr Devin Roza | Forum Activity | Replied: Sun, Apr 17 2016 11:28 PM

James Taylor:

Just did an encyclopedia, 540 Headwords coded in 1 sec. I'm suffering from perma-grin right now Big Smile

Glad it worked!! Big Smile

Posts 1151
Liam | Forum Activity | Replied: Thu, Apr 21 2016 4:49 PM

Fr Devin Roza:

James Taylor:

Fr Devin Roza:
This technique can also be used to insert the codes which Personal Books need to indicate that a certain heading is, for example, a Dictionary Head Word. If all the head words in your dictionary have the same formatting, in just a matter of a few minutes of work you could apply the information that the Logos Personal Book needs to recognize 1000s of head words.

Have you actually done this Fr Devin Roza? If so, Could you please post a screen shot of the find and replace window as you did for the above example?

I hadn't done it, but I did right now. Here are some test files, and the search. In the test file, the headwords we want to mark up are using Heading 1, which is what I will be replacing with the text Logos/Verbum needs to tell it this is an Encyclopedia headword. When you import the book, be sure to classify it as an encyclopedia.

Original Dictionary file: 5822.Test.docx

Dictionary file ready for Logos/Verbum: 6036.TestResult.docx

Here is the search you need to run to get from the original to the final file. Just click Replace All, and it will do all of them at once:

A few notes about this search:

- The search is for text that is Heading 1, any number of characters or words long, until it hits a carriage return (^13).

- The replace text uses \1 to indicate the variable (everything in between the () in the search string). Note that the replace string uses ^p instead of ^13. This is important, as ^13 does not work correctly in the replace string to indicate a carriage return (^13 doesn't work properly with styles in the replace box). 

Wow! That's great to know!

Posts 1394
James Taylor | Forum Activity | Replied: Mon, Sep 12 2016 10:26 AM

Fr Devin Roza:
Glad it worked!!

follow up question...

What would be the best procedure for the following scenario? When a book is set up with the bolded term in the beginnning of the sentence(paragraph) but it's not on a separate line. Using the normal find/replace wildcard syntax above doesn't work because there is no new paragraph following each term. Instead the term just runs into the sentence defining it. Is there a way to tell Word that after a certain font style to cause there to be a new paragraph? If there was I think your previous find/replace syntax for headwords would work.

For example, I need a way to automatically change every instance of this type of formatting...

to this type (which will work with you find/replace syntax)

I've searched all over online but apparently my Word terminology isn't right because I'm not seeing anything. I know it's got to be simple to add a new paragraph after a font style automatically

Logos 8  | Dell Inspiron 7373 | Windows 10 Pro 64, i7, 16GB, SSD | iPhone X | iMac 27" i7, 16GB, SSD | OS 10.13

Posts 1507
Forum MVP
Fr Devin Roza | Forum Activity | Replied: Mon, Sep 12 2016 10:59 AM

James Taylor:

Fr Devin Roza:
Glad it worked!!

follow up question...

What would be the best procedure for the following scenario? When a book is set up with the bolded term in the beginnning of the sentence(paragraph) but it's not on a separate line. Using the normal find/replace wildcard syntax above doesn't work because there is no new paragraph following each term. Instead the term just runs into the sentence defining it. Is there a way to tell Word that after a certain font style to cause there to be a new paragraph? If there was I think your previous find/replace syntax for headwords would work.

Yes, that's very possible to do. When you put your cursor in the "Find what" box, and then select the "Special" button, notice that the < indicates the beginning of a word, and > the end of a word. Then, using the "Format" button on the bottom left, you set your format to bold (note there are two places to set it - usually the first one works best for me).

So, to find a single word in Bold, and replace it with that same word in Bold plus Enter, you would replace for:

But a search like this by itself will almost certainly give you problems. The reason is you'll probably have Titles that have more than one word.

So, in these cases what I would do is start with the highest number of words, and work your way down. And, when you replace your text, replace it and change the format to something that's not bold, say Heading 2 or something not used elsewhere in the document, again setting this value using the Format button while your cursor is in the "Replace with" box. That way your subsequent search and replaces won't find it. At the end of the process, you can always change all of them back if you like. 

To search for two words in bold, it would be (<*>) (<*>)

Notice the space between the words. Then the replace string would be \1 \2^p

But start with 3 or 4 words, or however many would be the most. Then one less, and so on, all the way down to 1. 

Posts 1394
James Taylor | Forum Activity | Replied: Mon, Sep 12 2016 11:07 AM

Thank you for your thorough response and illustration. I'll give it a test drive :-)

Logos 8  | Dell Inspiron 7373 | Windows 10 Pro 64, i7, 16GB, SSD | iPhone X | iMac 27" i7, 16GB, SSD | OS 10.13

Posts 1507
Forum MVP
Fr Devin Roza | Forum Activity | Replied: Mon, Sep 12 2016 11:21 AM

My pleasure. Hope it works out for you.

Actually, now that I think of it, for two words, instead of (<*>) (<*>), it would be better to search for (<*> <*>). And so on for more words, or patterns - always in a single ().

That way you could always just leave the "Replace with" field the same. It would always just be \1^p

Posts 1394
James Taylor | Forum Activity | Replied: Mon, Sep 12 2016 11:37 AM

Fr Devin Roza:
a search like this by itself will almost certainly give you problems.

Ok, this has got me most of the way there. The only thing lacking is a way to specify to only find the bold words which are at the start of a paragraph which I'd assume is noted by a paragraph marker, because often there are other bolded words in the definitions which I don't want to replace with a new paragraph

Logos 8  | Dell Inspiron 7373 | Windows 10 Pro 64, i7, 16GB, SSD | iPhone X | iMac 27" i7, 16GB, SSD | OS 10.13

Posts 1507
Forum MVP
Fr Devin Roza | Forum Activity | Replied: Mon, Sep 12 2016 12:02 PM

James Taylor:

Fr Devin Roza:
a search like this by itself will almost certainly give you problems.

Ok, this has got me most of the way there. The only thing lacking is a way to specify to only find the bold words which are at the start of a paragraph which I'd assume is noted by a paragraph marker, because often there are other bolded words in the definitions which I don't want to replace with a new paragraph

Yeah, these can get tricky... the problem there is that the carriage return isn't bold, and when you search for a specific format, everything you find has to have that format. 

So, you need to fix that problem first. That is, you need to make every carriage return in the document bold!!

So, search for (^13) and replace it with \1 in bold.

Then, you can search for (^13<*>) in bold. But starting with whatever patterns are your longest as described above (e.g. (^13<*> <*> <*>) for three words.

Finally, you can search for (^13) and replace it with \1 but specifying that the format should be regular, to return your carriage returns to the way they were before. 

Posts 1394
James Taylor | Forum Activity | Replied: Mon, Sep 12 2016 1:01 PM

Fr Devin Roza:

search for (^13) and replace it with \1 in bold.

Then, you can search for (^13<*>) in bold. But starting with whatever patterns are your longest as described above (e.g. (^13<*> <*> <*>) for three words.

Finally, you can search for (^13) and replace it with \1 but specifying that the format should be regular, to return your carriage returns to the way they were before.

That did it!!!

I'm suffering from perma-grin right now... Big Smile AGAIN!

Logos 8  | Dell Inspiron 7373 | Windows 10 Pro 64, i7, 16GB, SSD | iPhone X | iMac 27" i7, 16GB, SSD | OS 10.13

Posts 612
John Brumett | Forum Activity | Replied: Mon, Oct 24 2016 6:30 PM

Okay so I need the find and replace for all scripture references.

Examples:

John 3:16               [[@Bible: John 3:16]]

Numbers 21:33-35  [[@Bible: Numbers 21:33-35]]

Posts 304
Bernhard | Forum Activity | Replied: Mon, Oct 24 2016 8:03 PM

That would mean to write quite an extensive macro to do it. But aren't those references recognized automatically without tagging in your personal book?

Posts 1394
James Taylor | Forum Activity | Replied: Mon, Oct 24 2016 8:52 PM

The goal is first to get the references to a line by themselves and then assign them to a heading style. Then the above procedure will work. I've gotten pretty creative with this process to make it happen.. for instance, often you will find (3:17) which has to be told to find ( and replace with John and force a new paragraph at a certain heading style, then remove ) at that heading style.  so you end up with John 3:17 at whichever heading style, on a line by itself.

Logos 8  | Dell Inspiron 7373 | Windows 10 Pro 64, i7, 16GB, SSD | iPhone X | iMac 27" i7, 16GB, SSD | OS 10.13

Posts 15805
Forum MVP
Keep Smiling 4 Jesus :) | Forum Activity | Replied: Tue, Oct 25 2016 12:04 AM

John Brumett:

Okay so I need the find and replace for all scripture references.

Examples:

John 3:16               [[@Bible: John 3:16]]

Numbers 21:33-35  [[@Bible: Numbers 21:33-35]]

Find What ([12 Songf]{2,8}[A-Z][a-z]{1,12}[ ][0-9]{1,3}[:][0-9\-]{1,7})

matches:

1 John 1:6-10

1 Corinthians 13:13

Song of Solomon 1:4

Find What ([A-Z][a-z]{1,12}[ ][0-9]{1,3}[:][0-9\-]{1,7})

matches:

John 3:16

Numbers 21:33-35

Psalms 119:169-176

Replace with [[@Bible: \1]]

Notice "Find Next" highlighted John 1:6-10 so prudent to verify Find highlights all of desired text to change before replacing.

Jude is one of the Bible Books that does not have a chapter number so searching for colon separator does not find Book verse(s).

Word wildcard matching FAQ => http://word.mvps.org/FAQs/General/UsingWildcards.htm

Be cautious with using * in wildcard search since * can match lots of characters.

Keep Smiling Smile

Posts 612
John Brumett | Forum Activity | Replied: Sat, Nov 26 2016 6:43 PM

Question for anyone or Keep Smiling for Jesus:

How do I run the prior Find and Replace if I want to keep the Scripture References but duplicate the milestones

For example  

Matthew 2:19-23; Luke  2:1-20, 39; John  2:1-11; 2 Peter 1:16-18   

I want to end up with

Matthew 2:19-23 [[@Bible Matthew 2:19-23]]; Luke  2:1-20, 39 [[@Bible Luke 2:1-20, 29]]; John  2:1-11 [[@Bible John 2:1-11]]; 2 Peter 1:16-18 [[@Bible 2 Peter 1:16-18]] 

Page 2 of 3 (45 items) < Previous 1 2 3 Next > | RSS