将此代码段从Perl转换为Javascript

时间:2019-03-10 03:52:05

标签: javascript perl

我知道许多编程语言,但我不知道的是Perl。如何在Javascript中实现以下Perl代码段?

my $minGroups = 3;
my %rexGroups = (
        upper => qr/[A-Z]/,
        lower => qr/[a-z]/,
        digit => qr/[0-9]/,
        other => qr/^[A-Za-z0-9]/,
);
my $nGroups = 0;
for my $re (keys %rexGroups) {
        ++$nGroups if ( $pass =~ m/$rexGroups{$re}/ );
}
if ( $nGroups < $minGroups ) {
        # indicate error
}
# indicate success

1 个答案:

答案 0 :(得分:1)

基本上,您发布的代码试图将给定的字符串与 from pathlib import Path #Returns the path of the directory, where your script file is placed mypath = Path().absolute() print('Absolute path : {}'.format(mypath)) #if you want to go to any other file inside the subdirectories of the directory path got from above method filePath = mypath/'data'/'fuel_econ.csv' print('File path : {}'.format(filePath)) #To check if file present in that directory or Not isfileExist = filePath.exists() print('isfileExist : {}'.format(isfileExist)) #To check if the path is a directory or a File isadirectory = filePath.is_dir() print('isadirectory : {}'.format(isadirectory)) #To get the extension of the file fileExtension = mypath/'data'/'fuel_econ.csv' print('File extension : {}'.format(filePath.suffix)) 进行匹配,如果它与3个或多个我们在different regexes中使用的正则表达式匹配,则应该给我们reg variable作为其他输出结果应该使用success

failure