所以我对Javascript世界非常新.我在代码战中练习,必须分析一个引脚,以确保它只包含数字,并且是4或6个字符.我查看了最聪明的代码,答案是:
function validatePIN(pin) {
return /^(\d{4}|\d{6})$/.test(pin)
}
Run Code Online (Sandbox Code Playgroud)
我以前从未见过"/ ^(\ d {4} |\d {6})$ /"位.谁能告诉我这是什么叫所以我可以自己研究一下,或者告诉我它是如何工作的细分?
我正在尝试编写一个程序来显示某些字符常量的数值(if语句中的那些).代码有效,除了一个问题.输出应该在列中很好地对齐,但如下所示,它不是.使列正确排列的最佳方法是什么?
这是我的代码:
#include <stdio.h>
#include <ctype.h>
int main() {
unsigned char c;
printf("%3s %9s %12s %12s\n", "Char", "Constant", "Description", "Value");
for(c=0; c<= 127; ++c){
if (c == '\n') {
printf("%3d %7s \t%s \t\t%s%03x\n", c,"\\n","newline","0x", c);
}else if (c == '\t'){
printf("%3d %7s \t%s \t\t%s%03x\n", c,"\\t","horizontal tab","0x", c);
}else if (c == '\v'){
printf("%3d %7s \t%s \t\t%s%03x\n", c,"\\v","vertical tab","0x", c);
}else if (c == '\b'){
printf("%3d %7s \t%s \t\t%s%03x\n", c,"\\b","backspace","0x", c);
}else if (c == '\r'){
printf("%3d %7s \t%s …Run Code Online (Sandbox Code Playgroud)