<TR class='passed'><TD>CAN signal</TD><TD>'DISP_RQ_GR_GRB' available in Inca.</TD><TD>PASSED</TD></TR>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
while (my $line = <$read_handle>) { if ($line =~ /class\=/ and $line =~ /CAN signal/) { my $Inca_Name; my $Inca_Vchk; my $Inca_Comment; # collect Signal Informations ($Inca_Vchk, $Inca_Name, $Inca_Comment)= $line =~ /^\<[A-Z]\s+[a-z]\=\'([a-z])\'\>\<[A-Z]\>[^0-9]<\/[A-Z]\>\<[A-Z]\>\'([a_zA-Z0-9_])\'\s+([^0-9])\<[^0-9]/; } }
2013-09-06T10:50:42 LauviaKönnte mir jemand diese Zeilen 12 und 13 mit regex vielleicht richtig schreiben?
1 2 3 4 5 6
# collect Signal Informations ($Inca_Vchk, $Inca_Name, $Inca_Comment)= $line =~ /^\<[A-Z]+\s+[a-z]+\=\'([a-z]+)\'\>\<[A-Z]+\>[^0-9]+<\/[A-Z]+\>\<[A-Z]+\>\'([a_zA-Z0-9_]+)\'\s+([^0-9]*?)\<[^0-9]+/; print "$Inca_Vchk $Inca_Name $Inca_Comment"; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
my $line = <<LINE; <TR class='passed'><TD>CAN signal</TD><TD>'DISP_RQ_GR_GRB' available in Inca.</TD><TD>PASSED</TD></TR> LINE # mehrzeiligen Regex mit Kommentaren my $regex = qr{ # wir brauchen die verwendete class class='([^']+)' # dann kommt erstmal uninteressantes (aber bitte sowenig wie moeglich) .*? # innerhalb einer tabellenzelle zwei strings einfangen <TD>'([^']+)'\s*([^<]+)</TD> }x; # ENDE Regex if ( my ($Inca_Vchk, $Inca_Name, $Inca_Comment) = $line =~ $regex ) { print $Inca_Vchk, "\n", $Inca_Name, "\n", $Inca_Comment, "\n", ; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
while (my $line = <$read_handle>) { my $Inca_Name; my $Inca_Vchk; my $Inca_Comment; #-------------------------------------------------------------------- # Variable check bloc #-------------------------------------------------------------------- if ($line =~ /class\=/ and $line =~ /CAN signal/) { #my %VarCheck; #my $Inca_Name; #my $Inca_Vchk; #my $Inca_Comment; #-----collect Signal Informations----------------------------------- ($Inca_Vchk, $Inca_Name, $Inca_Comment)= $line =~ /^<[A-Z]+\s+[a-z]+\=\'([a-z]+)\'><[A-Z]+>[^0-9]+<\/[A-Z]+><[A-Z]+>\'([a_zA-Z0-9_]+)\'\s+([^0-9]*?)<[^0-9]+/; #$VarCheck{'INCA_NAME'} = $Inca_Name; #$VarCheck{'INCA_VCHK'} = $Inca_Vchk; #$VarCheck{'INCA_COMMENT'} = $Inca_Comment; #$VarCheck{'SIGNAL'} = \@Signals; push(@Sig_Incadata, $Inca_Vchk, $Inca_Name, $Inca_Comment); print "Variable Check:\n\n$Inca_Vchk $Inca_Name $Inca_Comment\n\n"; # 1. Prüfstelle } #-------------------------------------------------------------------- # END Variable check bloc #-------------------------------------------------------------------- #-------------------------------------------------------------------- # Bus resolution check bloc #-------------------------------------------------------------------- if ($line =~ /class\=/ and $line =~ /ECU internal variable/) { my $Int_Vchk; my $Int_Name; my $Int_Comment; #-----collect Signal Informations----------------------------------- my $regexp = qr { class='([^']+)'.*?<TD>'([^']+)'\s*([^<]+)</TD> }x; # ENDE Regexp ($Int_Vchk, $Int_Name, $Int_Comment) = $line =~ $regexp; push(@Sig_Intdata, $Int_Vchk, $Int_Name, $Int_Comment); print "Resolution Check:\n\n$Int_Vchk $Int_Name $Int_Comment \n\n"; # 2. Prüfstelle } #-------------------------------------------------------------------- # END Bus resolution check bloc #-------------------------------------------------------------------- #-------------------------------------------------------------------- # Signal conversion check bloc #-------------------------------------------------------------------- if ($line =~ /class='/ and ($line !~ /ECU internal resolution/)and ($line =~ /$Sig_Incadata[1]/) and ($line =~ /\d+/)) { my $Sig_ConChk; my $Sig_ConCom; my $Bus_Value; my $Ecu_Value; my $deviation; #-----collect Signal Informations----------------------------------- my $regexp = qr { class='([^']+)'.*?<TD>(\d+)[^']+<TD>(\d+)<\/TD><TD>(\d+)<\/TD><TD>([^']+)</TD> }x; # ENDE Regexp (Problem liegt sicherlich hier) ($Sig_ConChk, $Bus_Value, $Ecu_Value, $deviation, $Sig_ConCom)= $line =~ $regexp; push(@table, $Sig_ConChk, $Bus_Value, $Ecu_Value, $deviation, $Sig_ConCom); print "Test:\n\n@Sig_Incadata\n@Sig_Intdata"; print "$table[1]\n"; # 3. Prüfstelle } #-------------------------------------------------------------------- # END Signal conversion check bloc #-------------------------------------------------------------------- } <>;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#! /usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Useqq = 1; # Baue den Regex nach und nach auf my $regex = qr{ class='([^']+)' # Klasse einfangen .*? # TODO: Bus value einfangen # TODO: ECU value einfangen # TODO: Deviation einfangen }x; my $i = 0; while ( my $line = <DATA> ) { if ( my @result = $line =~ $regex ) { print Dumper( \@result ); } else { warn "No match for: $line"; } } __DATA__ <TR><TH>Bus Signal</TH><TH>Bus Value</TH><TH>ECU Variable</TH><TH>ECU Value</TH><TH>Deviation</TH><TH>State</TH></TR> <TR class='failed'><TD>TEMP_EX</TD><TD>-40</TD><TD>Com_tEnvT_FA</TD><TD>-38.5</TD><TD>1.5</TD><TD>CONVERSION FAILED</TD></TR> <TR class='failed'><TD>TEMP_EX</TD><TD>-39.5</TD><TD>Com_tEnvT_FA</TD><TD>-38.5</TD><TD>1</TD><TD>CONVERSION FAILED</TD></TR> <TR class='failed'><TD>TEMP_EX</TD><TD>22</TD><TD>Com_tEnvT_FA</TD><TD>-38.5</TD><TD>60.5</TD><TD>CONVERSION FAILED</TD></TR> <TR class='failed'><TD>TEMP_EX</TD><TD>83.5</TD><TD>Com_tEnvT_FA</TD><TD>-38.5</TD><TD>122</TD><TD>CONVERSION FAILED</TD></TR> <TR class='failed'><TD>TEMP_EX</TD><TD>84.5</TD><TD>Com_tEnvT_FA</TD><TD>-38.5</TD><TD>123</TD><TD>CONVERSION FAILED</TD></TR> <TR class='failed'><TD>TEMP_EX</TD><TD>85</TD><TD>Com_tEnvT_FA</TD><TD>-38.5</TD><TD>123.5</TD><TD>CONVERSION FAILED</TD></TR>
1 2 3 4 5 6 7 8 9
#-----collect Signal Informations----------------------------------- my $regexp = qr { class='([^']+)'[^0-9]+<TD>([^,]+)<\/TD>[^0-9]+<TD>([^,]+)<\/TD><TD>([^,]+)<\/TD><TD>([^']+)</TD> }x; # ENDE Regexp ($Sig_ConChk, $Bus_Value, $Ecu_Value, $deviation, $Sig_ConCom)= $line =~ $regexp; push(@table, $Sig_ConChk, $Bus_Value, $Ecu_Value, $deviation, $Sig_ConCom);