Ханс, если вы не против, я использовал стиральную машину вашего соседа, названную perl:)
Отредактировано: Ниже псевдокода:
loop through input
if line contains 'if(' set skip=true
if skip= true do nothing
else
if line match '\b\d{5}\b' set s0=true
if line does not match s1 condition set s1=true
if line does not match s2 condition set s2=true
if s0,s1,s2 are true print line
if line contains '//endif' set skip=false
Учитывая файл input.txt :
tiago@dell:~$ cat input.txt
this is a text
it should match 12345
if(
it should not match 12345
//endif
it should match 12345
it should not match 12345.
it should not match ( blabla 12345 blablabla )
it should not match ( 12345 )
it should match 12345
И скрипт validator.pl:
tiago@dell:~$ cat validator.pl
#! /usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
sub validate_s0 {
my $line = $_[0];
if ( $line =~ \d{5/ ){
return "true";
}
return "false";
}
sub validate_s1 {
my $line = $_[0];
if ( $line =~ /\.$/ ){
return "false";
}
return "true";
}
sub validate_s2 {
my $line = $_[0];
if ( $line =~ /.*?\(.*\d{5.*?\).*/ ){
return "false";
}
return "true";
}
my $skip = "false";
while (<>){
my $line = $_;
if( $line =~ /if\(/ ){
$skip = "true";
}
if ( $skip eq "false" ) {
my $s0_status = validate_s0 "$line";
my $s1_status = validate_s1 "$line";
my $s2_status = validate_s2 "$line";
if ( $s0_status eq "true"){
if ( $s1_status eq "true"){
if ( $s2_status eq "true"){
print "$line";
}
}
}
}
if ( $line =~ /\/\/endif/) {
$skip="false";
}
}
Исполнение:
tiago@dell:~$ cat input.txt | perl validator.pl it should match 12345 it should match 12345 it should match 12345
Если вы спрашиваете, будет ли оператор распространения поддерживать неопределенные значения свойств «после распространения», они это сделают.
const original = { one: 1, two: 2, three: undefined, four: null };
console.log(original);
const withSpread = {five: 5, ...original };
console.log(withSpread);
console.log(typeof withSpread.three === 'undefined')
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators / Spread_syntax
Это оказалось неверным моим утверждением. Оператор Spread действительно расширяет поля со значением undefined
. Это было JSON.stringify()
удаление этих полей в одном из моих источников, что привело меня к неверному утверждению.
Для Express.js
пользователей; Вы можете использовать app.set('json replacer', (k, v) => v===undefined ? null : v);
, чтобы выразить stringify ваш ответ json, заменив undefined
значения на null
Или аналогично, вы можете использовать JSON.stringify({...}, (k, v) => v===undefined ? null : v)
, чтобы позволить ему замерить, заменив undefined
значения на [ 118]