Power Tip: Using variables to Search and Replace in Word

2»

Comments

  • Fr Devin Roza
    Fr Devin Roza Member, MVP Posts: 2,409

    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

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

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

  • Fr Devin Roza
    Fr Devin Roza Member, MVP Posts: 2,409

    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. 

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

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

  • John Brumett
    John Brumett Member Posts: 612 ✭✭

    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]]

  • Bernhard
    Bernhard Member Posts: 636 ✭✭

    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?

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

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

  • 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 [:)]

  • John Brumett
    John Brumett Member Posts: 612 ✭✭

    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 [[@BibleJohn 2:1-11]]; 2 Peter 1:16-18 [[@Bible 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 [[@BibleJohn 2:1-11]]; 2 Peter 1:16-18 [[@Bible 2 Peter 1:16-18]] 

    Personal Book (PB) text Matthew 2:19-23 would have the last preceding Bible milestone as location. Text Luke 2:1-20 , 29 would have Bible milestone of Matthew 2:19-23 so suggest placing @Bible milestone before verse reference.

    Bible milestone cannot skip verses: e.g. [[@BibleLuke 2:1-2029]] in Logos 7.3 Beta 1 receives PB compilation message

    [Warning] Unrecognized milestone Bible Luke 2:1-20, 29

    Screen shot of Word 2010 document showing Find Next highlighted that does not have the 2 of 2 Peter

    Microsoft implemented a subset of regular expression pattern in Word: e.g. every search term has to occur once so different Find is needed for Bible Books that have a numeric prefix. Also Find expression can receive error about being too complex

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

    Find What 

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

    matches

    2 Peter 1:16-18

    Wildcard Find explanation

    • [12 ]{2} looks for two occurrences of three characters
    • [A-Z][a-z]{1,12} looks for 1 to 12 occurrences of Alphabetic characters
    • [ ]{1,2} looks for one or two spaces (example had two spaces after Luke and John)
    • [0-9]{1,3} looks for one to three numbers
    • [:] looks for colon (separator between chapter and verse
    • [0-9\-]{1,7} looks for one to seven Numbers OR dash

    Bible reference Psalms 119:169-176 has chapter with three numbers and verses with three numbers.

    Parenthesis group wildcard find results for replacement

    • Result \1 => "2 Peter"
    • Result \2 => " "
    • Result \3 => "1:16-18"

    so Replace With

    [[@Bible \1 \3]]\1 \3

    uses first and third string result (so one or two spaces between book name and chapter is replaced with one space)

    [[@Bible 2 Peter 1:16-18]]2 Peter 1:16-18

    Find What

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

    Matthew 2:19-23

    Luke  2:1-20

    John  2:1-11

    Peter 1:16-18   

    Replace with

    [[@Bible \1 \3]]\1 \3

    OR

    [[@Bible: \1 \3]]\1 \3

    Colon after @Bible is optional.

    For example  

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

    @Bible milestones using book abbreviations:

    [[@Bible:Mt2.19-23]]Matthew 2:19-23; [[@Bible:Lk2.1-20]]Luke  2:1-20, 39; [[@Bible:Jn2.1-11]]John  2:1-11; [[@Bible:2P1.16-18]]2 Peter 1:16-18

    Logos Help has complete list of Bible Book abbreviations.

    Keep Smiling [:)]

  • Jean Gilbert
    Jean Gilbert Member Posts: 5

    Hi, I am looking for a find and replace that can take a verse range like 6:1-12 to [[@Bible:Genesis 6:1-12]]. Can anyone help me please? I will appreciate it greatly. Thanks.

  • David Goodman
    David Goodman Member Posts: 65

    Thanks, John, for laboriously spelling it out for someone like me to understand. I really appreciate it.

  • Hi, I am looking for a find and replace that can take a verse range like 6:1-12 to [[@Bible:Genesis 6:1-12]]. Can anyone help me please? I will appreciate it greatly. Thanks.

    Welcome to the Logos Bible Software forums [:D]

    Earlier reply in this thread => https://community.logos.com/forums/p/51122/867292.aspx#867292 has find and replace for conversion of Genesis 6:1-12 to [[@Bible:Genesis 6:1-12]]

    Find What

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

    Genesis 6:1-12

    Replace with

    [[@Bible \1 \3]]\1 \3

    OR

    [[@Bible: \1 \3]]\1 \3

    For verses without Bible Book, can Find references that have a colon ":" between chapter and verse range

    ([ ]{1,2})([0-9]{1,3}[:][0-9\-]{1,7})

    Replace with (includes Bible Book)

    [[@Bible Genesis \2]]Genesis \2

    OR

    [[@Bible:Genesis \2]]Genesis \2

    Keep Smiling [:)]

  • Jean Gilbert
    Jean Gilbert Member Posts: 5

    Thank you so much for all your help. I got it now. God bless you.

  • Thiago Samico
    Thiago Samico Member Posts: 59

    I am now getting used to Wildcards. Thanks to this post!

    Finding is not the problem at all, but I noticed that I am surely misunderstanding something in the "replace" part. 

    I have a Personal Bible that is formatted like:

    [[@Bible:Ge 1:7]]7. {{field-on:bible}}E assim aconteceu. Deus criou um espaço para separar as águas da terra das águas dos céus.{{field-off:bible}}

    It shows "7." before the verse text. 

    What I am trying to achieve is to replace that with 1:7 (this is a link) before the verse text. 

    So, the idea is to replace "7." with "[[1.7>>Bible: Ge 1:7]]

    I am using the following to find the string:

    (??[\@]Bible:)([A-Z][a-z]@&gt;)( )([0-9]@&gt;)(:)([0-9]@&gt;)([\]]{2})([0-9]@&gt;.)

    The string used for replace is:

    \1\2\3\4\5\6\7 [[\4:\6>>Bible: \2 \4\5\6]]

    The problem is that the result is:

    [[@Bible:Ge 1:7]] [[1:7>>Bible: Ge \4\5\6]] {{field-on:bible}}E assim aconteceu. Deus criou um espaço para separar as águas da terra das águas dos céus.{{field-off:bible}}

    I am certainly misusing the \4\5\6 part because it seems word stops recognizing them as representatives of the ( ) parts. 

    Please help me understand and solve that! 

    Thank you!