News, tips, advice, support for Windows, Office, PCs & more
Home icon Home icon Home icon Email icon RSS icon

We're community supported and proud of it!

  • Find & Replace

    • This topic has 30 replies, 2 voices, and was last updated 2 months ago by anonymous.
    Viewing 25 reply threads
    • Author
      Posts
      • #2344763
        Casey H
        AskWoody Plus

        Greetings All –

        I have an MS Word document that contains numerous Bible chapter and verse hyperlinks.  The website I use has changed its link structure, so now none of the links are functional.  Example: The old format finished like this for John, Chapter 19, Verse 1:

        /bible/john19:1

        The new format ends like this:

        /bible/john/19?1

        So two changes: a slash is now required between the Book (John) and the Chapter (19). and the colon between the Chapter and the Verse is replaced by a question mark.  Is there a sequence of characters I can type in the find/replace dialog that can globally  make these two changes.  As always, the help here is greatly appreciated.

        Casey H.

         

      • #2344813
        Paul T
        AskWoody MVP

        Press Alt F9 to reveal the hyperlink text. You should now be able to do a standard search/replace.

        Use this regex to find the colon between 2 sets of digits:
        (\d+):(\d+)
        Test that it finds what you expect.
        Use this as the replace string:
        /\1\?\2
        Test one replacement first.

        How it works
        The search is for one or more digits, colon, one or more digits. The plus means “and any additional of the same”.
        The brackets break the match into 2 capture groups with the colon in between.
        The replacement is a slash, the first capture group, question mark (escaped by a backslash), second capture group.

        cheers, Paul

        1 user thanked author for this post.
        • #2344880
          Casey H
          AskWoody Plus

          Hi Paul –

          Thanks for the input, but I’m not having any luck.  After Alt+F9, I pasted the first expression into the find box, and it came up with zero finds.  This current effort is using Office 2010.  I made no mention of that in my original post, as I thought it wouldn’t matter.

          Casey

        • #2344921
          anonymous
          Guest

          Hi Casey. No response yet from zeddy ( 😉 ), so – on a copy of your document – maybe try something like this:

          As Paul said above, press AltF9 to reveal hyperlink text

          Press CtrlH to open “Replace” tab on “Find and Replace” box

          Click More>> button (lower left corner of box)

          Check “Use wildcards” checkbox

          Then use this as Find string:
          //([a-z]*)([0-9]*):([0-9]*)”

          And use this as Replace string:
          //\1/\2?\3″

          Also, as Paul mentioned above, suggest you test one replacement first, and tweak as required…

          Hope this helps.

          1 user thanked author for this post.
          • #2344939
            anonymous
            Guest

            Hi again Casey.

            Better yet, proceed as above but…

            Use this as Find string:
            ([0-9]@):([0-9]@)”

            And use this as Replace string:
            /\1?\2″

            Above strings seemed to test successfully in Office 2013.

            Also, pls note: if search “couldn’t find what you’re looking for”, then (1) copy quotation mark from end of one of the visible hyperlinks in your document, and (2) use/paste copied quotation mark to replace trailing quotation mark in above Find and Replace strings (yeah, sounds stupid & unnecessary, but if “couldn’t find” then suggest you try it anyway).

            Hope this helps.

            1 user thanked author for this post.
            • #2345036
              anonymous
              Guest

              Fyi, an additional note on use of the trailing quotation mark…

              Q: So if use of the trailing quotation mark at the end of both the Find and Replace strings may cause a problem, why not just eliminate it completely?

              A: Well, use of the quotation mark at the end of both the Find and Replace strings is an attempt to confine the search operation to only select matching patterns contained in the embedded hyperlinks you actually want to modify.

              In other words, if the text of your document contains specific references to passages using chapter and verse notation similar to what you’re searching for in the hyperlinks (e.g., John 19:1), then deletion of the trailing quotation marks from the find and replace strings may inadvertently cause you to find and replace those text references as well.

              Hope this helps.

              1 user thanked author for this post.
      • #2344938
        Casey H
        AskWoody Plus

        Thanks for the input, but still no luck.  I pasted the find string and it returned a line of text  from within the document and then nothing else with a find next.

        Casey

      • #2344991
        Paul T
        AskWoody MVP

        Try searching for \d+
        Does it find digits?
        If not, try [0-9]+

        cheers, Paul

        1 user thanked author for this post.
      • #2345071
        Casey H
        AskWoody Plus

        I finally got it, but it took anonymous’ extra tip to replace the ending quote mark in the search bar with a quote mark from the end of one of the hyperlinks.  I don’t know if it was necessary or not, but I also replaced the quote mark at the end of the replace text in the same way.  I really appreciate it guys.  Now that Lent is upon us, I will be spending a lot of time in this document, and functional hyperlinks make things so much easier.

        As surmised, removing the quote at the end of the find text discovered the colons in the hyperlinks, but also in other places as well.  It also found numbers with more than a single digit, twice.  It found 16:3 and find next would locate 6:3.  I haven’t looked things over in great detail yet, but  the half dozen links I tried all work, and a few colons I saw in other places remained unchanged.

        Paul, the last recommendation I tried of yours didn’t come up with any hits.  Before all of my stuff gets synched, I think I’ll try some of these recommendations on my main computer, which is running Office 2016.  Thanks again–everyone.

        Casey

        • #2345097
          anonymous
          Guest

          It also found numbers with more than a single digit, twice. It found 16:3 and find next would locate 6:3.

          Yes, quite correct, but this shouldn’t cause a problem.

          Here’s why: because the initial/first Find operation grabs the full/complete chapter:verse character string(s), the subsequent Replace operation then should not only yield the desired result, but also – by replacing/modifying the previously-existing hyperlink – eliminate the possibility of subsequent “partial” grabs on the same string.

          Hope this helps.

          1 user thanked author for this post.
      • #2345092
        Casey H
        AskWoody Plus

        I checked with Word 2016  and got the same hits and misses.  Thanks to everyone’s input, I now have a very useful tool.  I don’t really understand the syntax, however, and would like to be able to apply this knowledge to future circumstances.  Is there a good tutorial somewhere that explains how all this works?

        Casey

         

      • #2345267
        Paul T
        AskWoody MVP

        If you don’t get any hits with my tests you are doing something wrong. Did you tick the wildcard box?

        Can you post a full hyperlink so we can tailor the regex?

        Regex is complex, but there are plenty of sites with instructions.
        I use this site to test: https://regex101.com/

        cheers, Paul

      • #2345444
        Casey H
        AskWoody Plus

        Originally I may not have checked use wild cards, but later I did (I think).

        The initial links (I think, because everything has been changed and I no longer have the original)  read like this: http://www.usccb.org/bible/john19:1

        The new address for same is https://bible.usccb.org/bible/john/19?1

        Before I came to you guys, I fixed the first part, making it:

        https://bible.usccb.org/bible/john19:1

        That left me with the need to insert a slash after john and replacing the colon after 19 with a question mark.

        Casey

      • #2345461
        Paul T
        AskWoody MVP

        Please check these searches with wildcard ticked.
        \d+
        [0-9]+

        Assuming the searches work then you can use this to find the hyperlink and change it.
        Find: (\/[a-z]+\/[a-z]+)(\d+):(\d+)
        Replace: \1\/\2\?\3

        cheers, Paul

        1 user thanked author for this post.
      • #2345497
        Casey H
        AskWoody Plus

        With the use wild cards box checked, neither \d+ nor

        [0-9]+ comes up with any findings.

        Casey

      • #2345592
        anonymous
        Guest

        Folks, with respect, I think perhaps there’s a simple explanation for your disconnect.

        While Paul is quite sensibly offering regular/typical regex search constructs, Casey is using MS Word. And Word regex is, in a word, weird. (Sufficiently weird, in fact, that I tend to think of it by a different name – rather than using “regular regex”, Word instead uses “weird wildcards”… 🙂 )

        So, Casey, you’re probably not doing anything wrong. And although Word might not be responding properly to Paul’s searches, Paul is not wrong…

        Word is wrong.

        Hope this helps.

        1 user thanked author for this post.
      • #2345796
        Casey H
        AskWoody Plus

        Indeed! I have received numerous solutions from Paul over the years.  I’m pretty sure that, out of frustration, I would have several PCs siting in the trash right now, if not for him.  I’d like to think that I’m at least half-way bright now when it comes to PC workings, thanks to the many inputs from so many Lounge members.  Paul in particular, always seems to come to my rescue.  I am very grateful.

        Casey

      • #2346026
        Casey H
        AskWoody Plus

        Clicking find next using \d@ just keeps finding the next small letter d.

        Casey

      • #2346223
        Paul T
        AskWoody MVP

        Try [0-9]@

        cheers, Paul

      • #2347121
        Casey H
        AskWoody Plus

        It looks like this thread is back in business.  The last several days, much of it was missing, so I thought best to just wait until things returned to normal.  Paul, I’ll give your last a try shortly, but wanted to get this in before I forgot about it.  Anonymous’ recommendation from above works, provided the quotation marks at the end of the strings are replaced by one from within the hyperlinks themselves:

        Better yet, proceed as above but…

        Use this as Find string:
        ([0-9]@):([0-9]@)”

        And use this as Replace string:
        /\1?\2″

        With a successful solution, I wanted to record it so as to have use of it in the future.  I was able to retrieve an earlier version of the document that still had the old links.  I pasted the above solution including the replaced ending quotation marks into a Word document for safekeeping.  When I tried using it, however, it no longer worked, but if I once again gathered replacement quote marks, it worked just fine.  I included a note to that effect in my reference document, resigned that I needed to amend all future efforts accordingly.  After thinking about it, I found this all to be unreasonable, and somehow, paste special came into my head.  I once again copied a quote from one of the hyperlinks, but consulted the paste special options.  There were two options: the default paste was something like unicode text, and the other was unformatted text.  I selected the latter, and now it all works like a charm.  I have a study document with functional hyperlinks and a reference document that has a working example for future find-replace issues.

        If you guys could oblige me one further insight.  I probably could figure it out except part of the added text is a slash, and I can’t figure out which of the slashes makes the process work, and which is the slash inserted into the hyperlink.  Paul, I’ll give your recommendation a try shortly.  Thanks.

        Casey

        • #2348804
          anonymous
          Guest

          If you guys could oblige me one further insight. I probably could figure it out except part of the added text is a slash, and I can’t figure out which of the slashes makes the process work, and which is the slash inserted into the hyperlink.

          Hi Casey.

          After just recently seeing your request for further insight (sorry, but I lost track of this thread when the site went sideways), I took the time to write up an explanation of how the find and replace strings work together to solve your problem, and then tried to post my reply… and then tried again… and then tried yet again…

          Unfortunately, though, each time my somewhat lengthy but harmless reply was blocked with the following message:
          ***
          Your message was blocked. Please contact the administrator via sb@askwoody.com
          *** Forbidden. anonymous@askwoody.com : E-mail does not exist. ***

          Assuming the site is operating properly (i.e., operating as intended) – and as my reply, submitted using the “Text” tab/box, was harmless – my only guess is that maybe my reply is being heuristicly bounced by some over-aggressive but under-performing site protection mechanism?

          Obviously I can’t troubleshoot the problem from my end. So unless someone with admin rights on the server side can find my reply in whatever bit bucket or bounce bin it got tossed into and restore it, then it appears that the site itself will not allow me to assist you further on this thread. 🙁

          But at least we were able to solve your original problem, so let’s call it a win anyway! 🙂

          Be well, my friend.

          1 user thanked author for this post.
      • #2347130
        Casey H
        AskWoody Plus

        Paul, [0-9]@ keeps finding the next number as it progresses through the document.

        Casey

      • #2347400
        Paul T
        AskWoody MVP

        “Next number” being a single digit, multiple digits or both?
        As long as it’s both you can use this as the find.
        (/[a-z]@/[a-z]@)([0-9]@):([0-9]@)

        And this as the replace.
        \1/\2\?\3

        To add a special character you have to “escape” it. Backslash is the escape character, as you can see in the replace.
        Ordinary slash does not seem to need to be “escaped”, question marks do.

        cheers, Paul

        • This reply was modified 2 months, 1 week ago by Paul T.
      • #2347770
        Casey H
        AskWoody Plus

        Somehow my yesterday’s response didn’t stick.  [0-9]@ returns only single digits.  E.g when it comes up on the number 300, first it finds the 3, then the first zero, then the 2nd.

        Casey

      • #2347883
        Paul T
        AskWoody MVP

        That’s not expected – Word is weird!
        How about ([0-9]@)

        cheers, Paul

      • #2347975
        Casey H
        AskWoody Plus

        Same thing–it just keeps finding one digit at a time, whether it’s just a single digit or part of a larger number.

        Casey

      • #2348078
        Paul T
        AskWoody MVP

        Did you tick the wildcard box in search?

        cheers, Paul

      • #2348213
        Casey H
        AskWoody Plus

        Yes, use wild cards is checked.  Do you suppose that like what I had discovered earlier about the pasted quote marks, it might have something to do with the format of the text.  Just for grins, I’m tempted to paste special your strings as unformatted text into a Word doc and try it from there.

        Casey

      • #2348223
        Casey H
        AskWoody Plus

        Well that didn’t accomplish anything.  Works the same way, finds one digit at a time regardless of how many digits a number contains.

        Casey

      • #2348266
        Paul T
        AskWoody MVP

        As I don’t have Word I can’t do any additional testing. Maybe someone else will have an idea.

        cheers, Paul

      • #2348329
        Casey H
        AskWoody Plus

        Thanks Paul–as always.  The one solution works, but I’m just not sure how easily I can adapt it to future circumstances.  I guess I’ll just cross that bridge when the time comes.

        Casey

      • #2356426
        macropod
        AskWoody_MVP

        In Word, with field codes displayed, a wildcard Find/Replace, where:

        Find = ([a-z])([0-9]@):([0-9])

        Replace = \1/\2?\3

        Cheers,
        Paul Edstein
        [Fmr MS MVP - Word]

    Viewing 25 reply threads

    Please follow the -Lounge Rules- no personal attacks, no swearing, no politics or religion.

    Reply To: Find & Replace

    You can use BBCodes to format your content.
    Your account can't use Advanced BBCodes, they will be stripped before saving.