Monday, 19 August 2013

Using Regex (or anything) to do an advanced find and replace

Using Regex (or anything) to do an advanced find and replace

I'm trying to find all things inside double quotes and replace it with a
link using it. I have over 500 lines of questions, so I don't want to do
it by hand.
Original php doc snippet:
$q2 = array ("What does Mars look like from Earth?",
"What is Mars's position relative to Earth?");
$q3 = array ("What does Mars's surface look like?",
"Show me a view of the surface of Mars.",
"Show me a picture of the surface of Mars.");
Formatting I want:
$q2 = array ("<a
href="answer.php?query=What+does+Mars+look+like+from+Earth%3F">What does
Mars look like from Earth?</a>",
<a
href="answer.php?query=What+is+Mars's+position+relative+to+Earth%3F">"What
is Mars's position relative to Earth?");
I tried using Regex, but without any previous experience with it, I was
unsuccessful. Using RegExr (my example) I came up with a find of:
"[A-Za-z0-9\s.\?']*" and a replace of: < a href=answer.php?query=$&>$&"
This just gave results like
$q2 = array (<a href=answer.php?query="What does Mars look like from
Earth?">"What does Mars look like from Earth?"</a>",
This is close, but not what I need. Hopefully someone knows what replace I
should use, or a better program to try. Any help would be appreciated.

No comments:

Post a Comment