packetstormer has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks
I really struggle with Regular Expressions! I have been battling this for a while but can't figure it
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)
test.test looks like this:#!/usr/bin/perl use strict; open (FH,"test.test") or die; while(<FH>) { if ($_ =~ /"(.+?)"/) { print "Matched: $1\n"; } }
output:This is line 1 "hello there" the is line 2 "goodbye, take care" this is line 3 "Jump, fox. Jump"
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!?Matched: hello there Matched: goodbye, take care Matched: Jump, fox. Jump
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regex: Changing $1
by toolic (Bishop) on Sep 04, 2013 at 14:25 UTC | |
Re: Regex: Changing $1
by hdb (Monsignor) on Sep 04, 2013 at 14:28 UTC | |
Re: Regex: Changing $1
by choroba (Cardinal) on Sep 04, 2013 at 14:25 UTC | |
Re: Regex: Changing $1
by davido (Cardinal) on Sep 04, 2013 at 15:11 UTC | |
Re: Regex: Changing $1
by packetstormer (Monk) on Sep 04, 2013 at 15:38 UTC | |
Re: Regex: Changing $1
by space_monk (Chaplain) on Sep 04, 2013 at 14:30 UTC | |
by hdb (Monsignor) on Sep 04, 2013 at 14:39 UTC | |
by choroba (Cardinal) on Sep 04, 2013 at 14:36 UTC | |
Re: Regex: Changing $1
by Anonymous Monk on Sep 04, 2013 at 14:44 UTC | |
by AnomalousMonk (Archbishop) on Sep 04, 2013 at 14:57 UTC |
Back to
Seekers of Perl Wisdom