Search and replace "" with " in random hyperlinks in a csv file
-
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.
-
@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">
? -
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 textThere 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. :-(
-
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.
-
@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 expressionNote, assumes links are all on one line.
-
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 fileSo then
href=""
becomeshref="
and"">
becomes>"
(the latter of which Alan already said)or, with search-mode in regular expression,
href=""([^"]+?)""
becomeshref="$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. -
@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.
-
@alan-kilborn Thank you for your help. My problem has solved. I am grateful.