OldChamp has asked for the wisdom of the Perl Monks concerning the following question:
Sorry for obviously not describing my problem clear enough, so here is the updated Question.
I can use perl 5.010 and there is no problem in reading the complete inputfile in memory.
I have text in a file of the following form, where the dots stands for a random amount of other text. After reading the input-file, all the newline characters are removed and my text is in $line.
.....P1p1/6P1/7P/5PK1/8 w - - 4 34"] {Weiß am Zug} * ..... 1n5P/1P4PK/1q6 b - - 2 42"] {Weiß am Zug} * ..... .......5K2/3R4 w - - 1 33"] {Weiß am Zug} * .....
If I have a space, followed by the letter b, followed by another space, as shown here in the third line, I want to substitute only the following 'Weiss' with 'Schwarz' and then continue to go through the text until there is another occurence of the pattern (space, followed by the letter b, followed by another space), when the next substition should follow.
So the core of the problem is: If I find a certain pattern-1 in the text, then go on till I find a certain pattern-2 and substitute this with a pattern-3. Do this again for the whole text. I have tried the following:
my $line = do { local $/; <>; }; $line =~ s/\n/ /g; # if ( $line =~ m/\sb\s/ ) # { # $line =~ s/Weiss/Schwarz/g; # } $line =~ s/(?<=\sb\s)Weiß/Schwarz/g; ... print $line;
but neither of this gives me the desired result, the text didn't change. How to solve this problem?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regex with condition
by jeffa (Bishop) on Nov 18, 2015 at 22:54 UTC | |
Re: Regex with condition
by AnomalousMonk (Archbishop) on Nov 18, 2015 at 23:55 UTC | |
Re: Regex with condition
by AnomalousMonk (Archbishop) on Nov 19, 2015 at 13:19 UTC | |
by OldChamp (Acolyte) on Nov 19, 2015 at 16:29 UTC | |
by AnomalousMonk (Archbishop) on Nov 19, 2015 at 20:39 UTC | |
by OldChamp (Acolyte) on Nov 19, 2015 at 23:26 UTC | |
by AnomalousMonk (Archbishop) on Nov 20, 2015 at 17:03 UTC | |
Re: Regex with condition
by Laurent_R (Canon) on Nov 19, 2015 at 08:18 UTC |
Back to
Seekers of Perl Wisdom