Power Tip: Using variables to Search and Replace in Word

Fr Devin Roza
Fr Devin Roza MVP Posts: 2,413
edited November 20 in English Forum

I created a Personal Book from a class I took this semester on the Acts of the Apostles. The professor's class notes used the European format for citing the Bible, where it is common to say Acts 1,1 instead of Acts 1:1.

Given that Logos Personal Books don't understand this format, I found myself with the difficulty of trying to replace all the commas with semicolons. Luckily with Microsoft Word this is extremely easy.

I told Microsoft Word to search for every occurrence of "a number followed by a comma followed by a number" and replace it with the same numbers, but with a semicolon in between.

Here is what the search looks like. Notice that the "Use Wildcards" option is selected.

There is documentation on doing this type of search and replace here: http://office.microsoft.com/en-us/word-help/find-and-replace-text-by-using-regular-expressions-advanced-HA102350661.aspx

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.

Tagged:
«1

Comments

  • Robert M. Warren
    Robert M. Warren Member Posts: 2,452 ✭✭✭

    Thanks for sharing this. I had not seen that type of citation style before, so now i'll be keeping an eye out for it.

    Using the variables is also handy for bible milestones. The key, as you have indicated, is consistent formatting.

    macOS (Logos Pro - Beta) | Android 13 (Logos Stable)

    Smile

  • fgh
    fgh Member Posts: 8,948 ✭✭✭

    the European format

    Please don't call it "the European format". It's as foreign to me as it is to Americans, if not more.

    I found myself with the difficulty of trying to replace all the commas with semicolons.

    You mean 'colons', not 'semicolons', but beside that:

    Personally, I would definitely prefer if people who prepare PB files for sharing didn't do that. It makes them useless for academic purposes, where quotes have to be exact. (What people do with their private PB files is, of course, up to them.)

    Another problem may be that complicated references may end up distorted if one doesn't check very carefully beforehand how the author has chosen to write such.

    The better method is to use search and replace to create a tag looking like [[Acts 1,1 >> Acts 1:1]].

    Mac Pro (late 2013) OS 12.6.2

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    fgh said:

    the European format

    Please don't call it "the European format". It's as foreign to me as it is to Americans, if not more.

    Didn't mean to offend. I've studied theology and Scripture in Europe for 4 years in 2 different universities and have seen this format used very often, almost exclusively in fact. I've never seen it in stuff from the US, however. It seems to be especially common in writings from Romance Languages, although I've seen it used in English writings as well (as in this case). It could be that it's something typical of the Romance Languages more than Europe per se, and which at times makes it into English documents due to the Romance Languages being so present here in Europe.

    fgh said:

    The better method is to use search and replace to create a tag looking like [[Acts 1,1 >> Acts 1:1]].

    If you know a quick way to do this please share. It becomes especially complicated when you get one citation after another, something which the simple solution I proposed handles perfectly (as "complicated references" get a space after the comma when it is not a Scriptural citation). In my case, for example, I replaced 1700 Scriptural citations with a format that Logos understands in a matter of minutes (most of the time being spent going through manually about 50 find and replaces to make sure I wasn't getting false positives), making the document extremely useful within Logos without spending much time. Perfect for many, many scenarios.

    BTW, the point of this post was more to share a method to quickly do intelligent search and replace in Word than to propose that this is something valid for every document and every case. As you pointed out, there are times in which this particular search would not be useful. But the goal is to open up peoples eyes so that they can apply the principles here in the scenarios that they encounter.

    If you or others want to share more examples of how you would do so in more complicated scenarios I'm sure it could be very helpful.

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    I was curious about the formatting question in Europe, so I investigated a little bit. Here's what I found.

    From what I've been able to discover, in German, French, Italian, Spanish, and Portuguese the typical citation format is Acts 1,1 with a comma, not a colon.

    In English of course the colon prevails. Even so, there are certain references to the comma being used instead of the colon as a possibility in English, especially in Europe. BTW, in Dutch it seems that the colon is also standard.

    Not really the topic of this thread, but nevertheless something that Logos might want to look into adapting for, especially if they get more into the mainland European languages.

  • NB.Mick
    NB.Mick MVP Posts: 15,968

    Thanks for sharing this - I'm a long-time user of word, but wasn't aware of the ability to use regular expressions in searches.

    From what I've been able to discover, in German, French, Italian, Spanish, and Portuguese the typical citation format is Acts 1,1 with a comma, not a colon

    Judging from other threads, you may add Czech to your list of languages that use the European notation.

    something that Logos might want to look into adapting for, especially if they get more into the mainland European languages.

    The Logos PB builder supports autodetection of bible references in European notation in some languages (e.g. Czech), but not all.

    Have joy in the Lord! Smile

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    NB.Mick said:

    The Logos PB builder supports autodetection of bible references in European notation in some languages (e.g. Czech), but not all.

    That's great news. What do you need to do to force this type of detection in the PB Builder? Change the language of the document in Word to Czech and turn auto-detection of the language off?

  • Robert M. Warren
    Robert M. Warren Member Posts: 2,452 ✭✭✭

    NB.Mick said:

    The Logos PB builder supports autodetection of bible references in European notation in some languages

    I was also happy to discover that the PB compiler also automatically detects citations using Roman numerals, (e.g. John iii. 16), which I find in Owen's work. Maybe it's a Puritan thing, but I have also seen it as late as the late 1950s in a work by J.I. Packer.

    macOS (Logos Pro - Beta) | Android 13 (Logos Stable)

    Smile

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    NB.Mick said:

    The Logos PB builder supports autodetection of bible references in European notation in some languages (e.g. Czech), but not all.

    I ran a few tests, but was not able to make this work. I tried to import English documents with the Acts 1,1 format as if they were Spanish, or Czech, etc (the text still being in English). Logos either did not recognize the references at all, or recognized them wrong (i.e. Acts 1,1 Logos understands as Acts 1).

    I then created a brief document in Spanish with "Hechos 1,1" and a few other similar citations, and imported it into Logos PBB, setting the language in PBB to Spanish. Same problem, Logos was expecting the "Hechos 1:1" format.

  • NB.Mick
    NB.Mick MVP Posts: 15,968


    NB.Mick said:

    The Logos PB builder supports autodetection of bible references in European notation in some languages (e.g. Czech), but not all.

    I ran a few tests, but was not able to make this work.

    Devin,

    according to my tests, the PB compiler just looks at the document language you give when you complie the document and disregards the Word settings.

    I'm not on my Logos computer right now to show you with screenshots, but you may have a look in the following thread: http://community.logos.com/forums/p/48257/357856.aspx#357856 - I linked to the post that shows Czech references

    Hope this helps,

    Mick

    Have joy in the Lord! Smile

  • BillS
    BillS Member Posts: 3,805 ✭✭✭

    This technique can also be used

    Thanks so much! I adapted the technique to remove trailing spaces after superscript verse numbers. Works great!

    I'd wondered how to use wild cards... your post led me to try them, & it's powerful! 

    Thanks again!

    [H] [8-|]

    Grace & Peace,
    Bill


    MSI GF63 8RD, I-7 8850H, 32GB RAM, 1TB SSD, 2TB HDD, NVIDIA GTX 1050Max
    iPhone 12 Pro Max 512Gb
    iPad 9th Gen iOS 15.6, 256GB

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    Glad it could be of use. If you have a moment, post a screenshot of your search and replace window.

    I think it would probably be helpful if we can get together a bunch of examples.

  • BillS
    BillS Member Posts: 3,805 ✭✭✭

    post a screenshot of your search and replace window

    image

    To remove the trailing space, I added a space at end of the "Find What" term. The "Replace With" term has no trailing space. Problem solved, so long as Logos keeps putting a superscript space after the superscript number. And since I don't care whether the number is single or double digit (this Find What only finds the least significant digit), it works slick.

    Grace & Peace,
    Bill


    MSI GF63 8RD, I-7 8850H, 32GB RAM, 1TB SSD, 2TB HDD, NVIDIA GTX 1050Max
    iPhone 12 Pro Max 512Gb
    iPad 9th Gen iOS 15.6, 256GB

  • Stephen Chaffer
    Stephen Chaffer Member Posts: 75

    Dear Sir

    I'm new to preparing PPB, I would like more information about preparing the proper terms, have you further adice on the subject.

    Also, why does my Hebrew Text not appear in my commentary I'm making, there's space and if one clicks on it, it appears in a narrow box on the right?

    (1-9) /1 What's this really mean in plain English...Thanks for your ideas and any help you msy be able to render

    Stephen

  • steve clark
    steve clark Member Posts: 3,591 ✭✭✭

    Hi Stephen,

    i am not the one you were addressing, but this might possibly be helpful for you.

    I'm new to preparing PPB, I would like more information about preparing the proper terms, have you further adice on the subject.

    A. Read the Personal Book wiki page for details on using PBs.

    B. Get the PB macros for Word.

    C. If you don't understand a particular feature, then start a new post here on the forum and ask your question. Give as much details as possible so others can help.

     

    Also, why does my Hebrew Text not appear in my commentary I'm making

    You might start by copying Hebrew text from Logos4 and pasting it into your Word docx file. If you are familiar with typing Hebrew directly into Word, then make sure you are using the same font that is used in Logos4.
    [Below in the image you can see that my PB has Hebrew entered into it. Layered above my PB is Word where i show the font selection box that Word provides, relative to text that i have pasted from L4 into Word.]

    image

    (Click on the above picture to have your browser enlarge the picture)

     

    QLinks, Bibl2, LLR, Macros
    Dell Insp 17-5748, i5, 1.7 GHz, 8G RAM, win 8.1

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413


    (1-9) /1 What's this really mean in plain English...Thanks for your ideas and any help you msy be able to render


    [0-9] indicates that Word should look for any single number, anywhere from 0-9. As there is a space following the [0-9], Word will also look for a space. Also notice that the "Superscript" format is being searched for.

    The \1 refers to the first Wildcard search it did above (in this case "[0-9]" without the space).

    What Word will do with this search is look for Superscript formatted text that consists of any number plus a space. It will then replace it with that same number without the space.

    What's special about this search is that it will replace "1 " with "1", "2 " with "2 ", etc., all with just one search.

    In my search it is just slightly more complicated. It is looking for any number followed by a comma and then followed by any number. It will replace it with the same two numbers but with a colon inbetween instead of the comma. In my case the replace string is "\1:\2". \1 refers to the first number, \2 to the second, and so on. Notice that this 1 search and replace that I did would otherwise have required 100 different search and replaces had I not used variables.

    Again, more documentation and examples are here: http://office.microsoft.com/en-us/word-help/find-and-replace-text-by-using-regular-expressions-advanced-HA102350661.aspx

  • (1-9) /1 What's this really mean in plain English

    The search syntax:

    ([0-9]),([0-9])

    looks for one number [0-9] that is followed by a comma, which is followed by one number [0-9]

    Note: [0-9] looks for a range of characters from 0 through 9, which is equivalent to specifying all numeric digits [0123456789].

    The reference  /1 refers to what was found inside the first set of parenthesis while /2 refers to the second set of parenthesis so the chapter and verse numbers can be different.

    While formatting New Testament in a personal book Bible => American Standard Version 1901 - Personal Bible without Chapter and Verse #'s decided to add chapter milestones so wanted tag for the first verse in a chapter

    @{{bible-on}}[[@BibleKJV:Mt28:1]]

    to be preceded by a chapter milestone and a space:

    [[@BibleKJV:Mt28]] {{bible-on}}[[@BibleKJV:Mt28:1]]

    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

    The second set of parenthesis (??[\@]BibleKJV:[0-9,A-Z]{1,2}[a-z]{1,2}[0-9]{1,3}) searches for:

    • ??  => two wildcard characters that can find [[ since Microsoft Word 2010 has a recursion limit for correctly parsing regular expressions with escaped characters (milestones are enclosed in brackets)
    • [\@]  => escaped syntax to search for @ special character (begins milestone tag)
    • BibleKJV:  => specific string of characters (Bible milestone using KJV versification)
    • [0-9,A-Z]{1,2} => one or two character(s): number OR capital letter (initial capital letter of Book plus a leading number)
    • [a-z]{1,2}  => one or two lower case letters (rest of Book abbreviation in lower case)
    • [0-9]{1,3}  => one, two, or three numbers (chapter number)


    The fourth set of parenthesis ([\]]{2}) searches for:

    • [\]]{2}  => escaped syntax to search for two ]] closing brackets (milestones are enclosed in brackets)

    The replacement string /2/4 /1/2/3/4 specifies that the second and fourth set of search results should be followed by a space then the original search results (copy the Bible milestone for verse 1 in a chapter to become the chapter milestone, which does not have a verse number).

    image


    For milestone tagging, personally used two or three character abbreviations for books with initial capital => http://www.logos.com/L4/support/biblebookabbrev

    Note: thread => American Standard Version 1901 - Personal Bible without Chapter and Verse #'s now has an updated New Testament file because my initial search string missed book abbreviations that began with a number.

    Keep Smiling [:)]

  • Stephen Chaffer
    Stephen Chaffer Member Posts: 75

    Hi 

    Thanks for your help, I knew these were possible but didn't know how it ticked.

    Also, your explanation is very helpful, and you've made it easy to follow

    Thanks again!

    Stephen

  • fgh
    fgh Member Posts: 8,948 ✭✭✭

    fgh said:

    Please don't call it "the European format". It's as foreign to me as it is to Americans, if not more.

    Didn't mean to offend.

    I know. I'm just a bit sensitive to Europe being treated as if it was one nation. It isn't. After all, we've spent most of history at each others' throats. There are vast cultural differences even between Sweden and Norway, or Sweden and Finland.

    It could be that it's something typical of the Romance Languages more than Europe per se

    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.

    If you know a quick way to do this please share.

    I use LibreOffice, not Word, and I do it so seldom that I have to look it up each time, so I'm afraid I can't. It's easy enough once you've got the strings right, though.

    something which the simple solution I proposed handles perfectly (as "complicated references" get a space after the comma when it is not a Scriptural citation)

    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.

     

    Mac Pro (late 2013) OS 12.6.2

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    fgh said:

    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 said:

    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.

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    " rel="nofollow">Keep Smiling 4 Jesus :) said:

    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!

  • James Taylor
    James Taylor Member Posts: 1,408 ✭✭✭

    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 10  | Dell Inspiron 7373 | Windows 11 Pro 64, i7, 16GB, SSD | iPhone 13 Pro Max

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    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). 

  • James Taylor
    James Taylor Member Posts: 1,408 ✭✭✭

    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 10  | Dell Inspiron 7373 | Windows 11 Pro 64, i7, 16GB, SSD | iPhone 13 Pro Max

  • James Taylor
    James Taylor Member Posts: 1,408 ✭✭✭

    Just did an encyclopedia, 540 Headwords coded in 1 sec. I'm suffering from perma-grin right now [:D]

    Logos 10  | Dell Inspiron 7373 | Windows 11 Pro 64, i7, 16GB, SSD | iPhone 13 Pro Max

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

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

    Glad it worked!! [:D]

  • Liam
    Liam Member Posts: 1,439 ✭✭✭

    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!
  • James Taylor
    James Taylor Member Posts: 1,408 ✭✭✭

    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 10  | Dell Inspiron 7373 | Windows 11 Pro 64, i7, 16GB, SSD | iPhone 13 Pro Max

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    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. 

  • James Taylor
    James Taylor Member Posts: 1,408 ✭✭✭

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

    Logos 10  | Dell Inspiron 7373 | Windows 11 Pro 64, i7, 16GB, SSD | iPhone 13 Pro Max