Community
    • Login

    Search and replace "" with " in random hyperlinks in a csv file

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 3 Posters 933 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Waqas SaeedW
      Waqas Saeed
      last edited by

      I have lots of random URLs in a CSV file which I have in a CSV file which has been exported from a MS SQL server. I am trying to import the CSV file in WordPress but some html code is not working in CSV file. Here it is an example.
      <a href=““https://www.facebook.com/xyz/dmz””>linkAA </a>
      If I change this html code to
      <a href=“https://www.facebook.com/xyz/dmz”>linkAA </a>
      After replacing “” with " the code works fine. I can find replace the first “” with simple find and replace but unable to find a solution to replace the second “” at the end of the URL.

      Can somebody help. All URLs are random and are from different websites not just facebook.

      Any help will be much appreciated.

      Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Waqas Saeed
        last edited by

        @waqas-saeed

        @waqas-saeed said in Search and replace "" with " in random hyperlinks in a csv file:

        fter replacing “” with " the code works fine. I can find replace the first “” with simple find and replace but unable to find a solution to replace the second “” at the end of the URL.

        Any reason you can’t simply replace "" with "?
        Or ""> with ">?

        1 Reply Last reply Reply Quote 3
        • PeterJonesP
          PeterJones @Waqas Saeed
          last edited by

          @waqas-saeed ,

          If I view-source, I think your example data is using two ASCII double-quotes in a row, "", not the smart quotes that the forum shows, “” – following the advice linked in the “Please Read This Before Posting” would have helped you show your data without ambiguity.

          That said, FIND="", REPLACE=", and then FIND-NEXT/REPLACE or a global REPLACE ALL, will work in normal search mode – unless you have other places where you want to keep "", in which case it wouldn’t work… but do you really ever want to keep "" in your text

          There are no commas (or other separator-character characters) shown in your data, so I’m unsure why you mentioned “csv”

          Ah, @Alan-Kilborn’s less long-winded reply beat me to it. :-(

          1 Reply Last reply Reply Quote 2
          • Waqas SaeedW
            Waqas Saeed
            last edited by Waqas Saeed

            basically problem is I have “” everywhere in the CSV file so I cannot just find and replace “” in one go. I just need to replace “” at just these two spots where ever there is a <a href=“" tag used in the CSV file.

            Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn @Waqas Saeed
              last edited by

              @waqas-saeed said in Search and replace "" with " in random hyperlinks in a csv file:

              basically problem is I have “” everywhere in the CSV file so I cannot just find and replace “” in one go

              Ah, then maybe this works, and is simplest to understand:

              find: (?-is)<a href=""(.+?)"">
              repl: <a href="${1}">
              mode: regular expression

              Note, assumes links are all on one line.

              1 Reply Last reply Reply Quote 1
              • PeterJonesP
                PeterJones @Waqas Saeed
                last edited by

                @waqas-saeed ,

                I have “”

                No you don’t. You have "" in many places in the file. Search/replace requires precision in your thinking and phrasing and typing.

                If you are going to type quotes in the forum, if you want there to be no confusion, then you must read the “Read Before Posting” and the other FAQs it links, because otherwise the forum will convert your "" to “”, which are not the same pairs of characters.

                I have "" everywhere in the CSV file

                So then href="" becomes href=" and ""> becomes >" (the latter of which Alan already said)

                or, with search-mode in regular expression, href=""([^"]+?)"" becomes href="$1"

                If you don’t have any other HTML attributes (like classes, styles, and the like), then Alan’s most-recent regular expression will work. But if your code is really <a class="foobar" href=""https://some.url/here"" style="color: red"> then his regex won’t work, so you’ll want to try mine.

                Alan KilbornA 1 Reply Last reply Reply Quote 2
                • Alan KilbornA
                  Alan Kilborn @PeterJones
                  last edited by Alan Kilborn

                  @peterjones said in Search and replace "" with " in random hyperlinks in a csv file:

                  No you don’t. You have “” in many places in the file. Search/replace requires precision in your thinking and phrasing and typing.

                  I’ve given up trying to get people to understand that posting here on the forum will muck with certain data unless they “black box” it:

                  This won't mess with my data -- well, too much anyway
                  

                  or red-text it:

                  This won't mess with my data -- well, too much anyway

                  Details on doing the above formatting are probably found HERE.

                  Waqas SaeedW 1 Reply Last reply Reply Quote 0
                  • Waqas SaeedW
                    Waqas Saeed @Alan Kilborn
                    last edited by

                    @alan-kilborn Thank you for your help. My problem has solved. I am grateful.

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors