Thread Regex Problem (4 answers)
Opened by crojay at 2011-09-15 16:25

Gast langmic
 2011-09-15 17:44
#152469 #152469
Hi,

folgendes tut bei mir:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use strict;
use warnings;
use File::Slurp;

my $searchStr = "value=\".*\"";
my $suffix = "YEPPA";
my $replaceStr = "value=\"_" . $suffix . "\"";

my @lines = read_file( \*DATA );

foreach my $line(@lines){
    print "line --> $line";
    $line =~ s/$searchStr/$replaceStr/g;
    print "line --> $line";
}

__DATA__
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="ServiceId.suffix" value="_TEST" />
  </appSettings>
</configuration>


Ergibt folgenden output:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
E:\develop>perl test.pl
line --> <?xml version="1.0" encoding="utf-8" ?>
line --> <?xml version="1.0" encoding="utf-8" ?>
line --> <configuration>
line --> <configuration>
line --> <appSettings>
line --> <appSettings>
line --> <add key="ServiceId.suffix" value="_TEST" />
line --> <add key="ServiceId.suffix" value="_YEPPA" />
line --> </appSettings>
line --> </appSettings>
line --> </configuration>
line --> </configuration>


Grüße,
Michael

View full thread Regex Problem