• Login
Community
  • Login

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

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 3 Posters 937 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.
  • W
    Waqas Saeed
    last edited by Jan 5, 2022, 2:04 PM

    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.

    A P 2 Replies Last reply Jan 5, 2022, 2:14 PM Reply Quote 0
    • A
      Alan Kilborn @Waqas Saeed
      last edited by Jan 5, 2022, 2:14 PM

      @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
      • P
        PeterJones @Waqas Saeed
        last edited by Jan 5, 2022, 2:15 PM

        @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
        • W
          Waqas Saeed
          last edited by Waqas Saeed Jan 5, 2022, 3:09 PM Jan 5, 2022, 3:08 PM

          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.

          A P 2 Replies Last reply Jan 5, 2022, 3:17 PM Reply Quote 0
          • A
            Alan Kilborn @Waqas Saeed
            last edited by Jan 5, 2022, 3:17 PM

            @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
            • P
              PeterJones @Waqas Saeed
              last edited by Jan 5, 2022, 3:20 PM

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

              A 1 Reply Last reply Jan 5, 2022, 3:38 PM Reply Quote 2
              • A
                Alan Kilborn @PeterJones
                last edited by Alan Kilborn Jan 5, 2022, 3:38 PM Jan 5, 2022, 3:38 PM

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

                W 1 Reply Last reply Jan 5, 2022, 3:56 PM Reply Quote 0
                • W
                  Waqas Saeed @Alan Kilborn
                  last edited by Jan 5, 2022, 3:56 PM

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

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