如果发现文本上有任何单词,我该怎么说?



我正在尝试检查文本上是否包含任何单词console.log(1)console.log(2)为 false ,但是我得到了1,2,1,2,因为它是匹配的,并且有些失败,但我希望如果只包含给定单词中的一个单词,那么ok,但如果不是假的,但我得到真, 假

var keywords = ['aslr', 'ida pro', 'gdb', 'windbg', 'immunity debugger', 'boofuzz', 'peach fuzzer', 'winafl', 'python', 'assembly', 'penetration testing', 'exploits', 'metasploit', 'metasploit framework', 'ethical hacker', 'pentest', 'computer security', 'hacking', 'oscp', 'osce', 'osee', 'penetration testing', 'offensive security', 'mitre att&ck', 'vulnerability research', 'vulnerability researcher', 'fuzzing', 'clang', 'llvm', 'address sanitizer', 'afl', 'fuzzers', 'penetration tester']
var data = "a successful cybersecurity consultancy are seeking an experienced penetration tester to join their melbourne practice on a permanent basis. work across a wide portfolio of clients and help them in identifying security vulnerabilities by conducting web application, network security, and wireless penetration testing. key responsibilities/duties: work with a diverse range of customers to identify and solve security problems, both in-person and remotely undertake application, network, and wireless penetration testing and vulnerability assessments prepare high-quality reports detailing security issues, making recommendations and identifying solutions perform social engineering and physical security assessments and/or undertake secure code reviews, where appropriate key requirements: demonstrated experience in penetration testing penetration testing certifications such as oscp, osce, ceh, sans, crest crt or cct a proven passion for cybersecurity with regular attendance at security events and/or memberships to the likes of owasp understanding of information security principles and security technologies 2 + years' work experience in security what the company can offer you: ongoing one-on-one training and development a budget for training courses/certifications flexible working arrangements and the option to work-from-home the opportunity to work in a collaborative environment with experienced security professionals if this position sounds of interest, please click 'apply' or email your cv directly to charlotte@preactarecruitment.com."
for (var i = 0; i < keywords.length; i += 1) {
if (data.indexOf(keywords[i])) {
console.log(1)
}
console.log(2)
}

不要记录在循环中,而是使用常规变量来计算匹配项,然后检查变量。

例如:

let matches = 0;
for (var i = 0; i < keywords.length; i += 1) {
// Note that indexOf returns -1 on failure, not false or zero
if (data.indexOf(keywords[i]) !== -1) {
matches++;
}
}
if(matches) {
console.log(1);
}
else {
console.log(2);
}

您可以将someincludes结合使用,以检查keywords中的单词是否在data中,然后记录所需的输出:

var keywords = ['aslr', 'ida pro', 'gdb', 'windbg', 'immunity debugger', 'boofuzz', 'peach fuzzer', 'winafl', 'python', 'assembly', 'penetration testing', 'exploits', 'metasploit', 'metasploit framework', 'ethical hacker', 'pentest', 'computer security', 'hacking', 'oscp', 'osce', 'osee', 'penetration testing', 'offensive security', 'mitre att&ck', 'vulnerability research', 'vulnerability researcher', 'fuzzing', 'clang', 'llvm', 'address sanitizer', 'afl', 'fuzzers', 'penetration tester'];
var data = "a successful cybersecurity consultancy are seeking an experienced penetration tester to join their melbourne practice on a permanent basis. work across a wide portfolio of clients and help them in identifying security vulnerabilities by conducting web application, network security, and wireless penetration testing. key responsibilities/duties: work with a diverse range of customers to identify and solve security problems, both in-person and remotely undertake application, network, and wireless penetration testing and vulnerability assessments prepare high-quality reports detailing security issues, making recommendations and identifying solutions perform social engineering and physical security assessments and/or undertake secure code reviews, where appropriate key requirements: demonstrated experience in penetration testing penetration testing certifications such as oscp, osce, ceh, sans, crest crt or cct a proven passion for cybersecurity with regular attendance at security events and/or memberships to the likes of owasp understanding of information security principles and security technologies 2 + years' work experience in security what the company can offer you: ongoing one-on-one training and development a budget for training courses/certifications flexible working arrangements and the option to work-from-home the opportunity to work in a collaborative environment with experienced security professionals if this position sounds of interest, please click 'apply' or email your cv directly to charlotte@preactarecruitment.com.";
if (keywords.some(word => data.includes(word))) console.log(1);
else console.log(2);

您可以使用变量来检查找到的关键字数量,因为您只需要一个关键字,如果 count 的值超出1则脱离循环并相应地显示值

var keywords = ['aslr', 'ida pro', 'gdb', 'windbg', 'immunity debugger', 'boofuzz', 'peach fuzzer', 'winafl', 'python', 'assembly', 'penetration testing', 'exploits', 'metasploit', 'metasploit framework', 'ethical hacker', 'pentest', 'computer security', 'hacking', 'oscp', 'osce', 'osee', 'penetration testing', 'offensive security', 'mitre att&ck', 'vulnerability research', 'vulnerability researcher', 'fuzzing', 'clang', 'llvm', 'address sanitizer', 'afl', 'fuzzers','penetration tester']
var data = "a successful cybersecurity consultancy are seeking an experienced penetration tester to join their melbourne practice on a permanent basis. work across a wide portfolio of clients and help them in identifying security vulnerabilities by conducting web application, network security, and wireless penetration testing. key responsibilities/duties: work with a diverse range of customers to identify and solve security problems, both in-person and remotely undertake application, network, and wireless penetration testing and vulnerability assessments prepare high-quality reports detailing security issues, making recommendations and identifying solutions perform social engineering and physical security assessments and/or undertake secure code reviews, where appropriate key requirements: demonstrated experience in penetration testing penetration testing certifications such as oscp, osce, ceh, sans, crest crt or cct a proven passion for cybersecurity with regular attendance at security events and/or memberships to the likes of owasp understanding of information security principles and security technologies 2 + years' work experience in security what the company can offer you: ongoing one-on-one training and development a budget for training courses/certifications flexible working arrangements and the option to work-from-home the opportunity to work in a collaborative environment with experienced security professionals if this position sounds of interest, please click 'apply' or email your cv directly to charlotte@preactarecruitment.com."
let matchCount = 0
for (var i = 0; i < keywords.length; i += 1) {
if (data.includes(keywords[i])) {
matchCount++
}
if (matchCount > 1) break
}
console.log(matchCount === 1 ? 1 : 2)

最新更新