perlquestion
packetstormer
<p>Hello Monks</p>
<p>I really struggle with Regular Expressions! I have been battling this for a while but can't figure it</p>
<p>I need to match a string between two double quotes then make changes to that matched string. However, it is proving difficult. See below, I capture the line between quotes into a variable then make changes to it. I then want to change that back in the line (to write out to another file later)
<br />
<code>
#!/usr/bin/perl
use strict;
open (FH,"test.test") or die;
while(<FH>) {
if ($_ =~ /"(.+?)"/) {
print "Matched: $1\n";
}
}
</code>
test.test looks like this:
<code>
This is line 1 "hello there"
the is line 2 "goodbye, take care"
this is line 3 "Jump, fox. Jump"
</code>
output:
<code>
Matched: hello there
Matched: goodbye, take care
Matched: Jump, fox. Jump
</code>
How do I modify $1 back into $_ to write out? I have tried assigning $1 to $new and then matching that on the original string but I can't figure it out!?