javascript JS_RegExp_function _ && _ negative_lookahead

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript JS_RegExp_function _ && _ negative_lookahead相关的知识,希望对你有一定的参考价值。

/*
 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test
 * Jack(?!Chen)
 * Negative lookahead | only mach Jack OR Jack+(anything not match `Chen`)
 */

let str = 'JackBlack is not my friend.';
let tmpStr = 'JackChen is my friend.';
let withoutG= /Jack(?!Chen)/;
let withG = /Jack(?!Chen)/g;
let withG2 = /Jack(?!Chen)/g;

for(let i = 0; i < 3; i ++) {
	console.log(`Normal WithoutG ${i}th  ` + withoutG.test(str));
}

console.log('===================');

for(let i = 0; i < 3; i ++) {
	console.log(`Normal WithG ${i}th  ` + withG.test(str));
	console.log(`Temp WithG ${i}th  ` + withG.test(tmpStr));
	console.log(`Normal WithG2 ${i}th  ` + withG2.test(str));
}


// Normal  WithoutG 0th  true
// Normal  WithoutG 1th  true
// Normal  WithoutG 2th  true
// ===================
// Normal  WithG 0th  true
// Temp  WithG 0th  false
// Normal  WithG2 0th  true
// Normal  WithG 1th  false
// Temp  WithG 1th  false
// Normal  WithG2 1th  false
// Normal  WithG 2th  false
// Temp  WithG 2th  false
// Normal  WithG2 2th  true

以上是关于javascript JS_RegExp_function _ && _ negative_lookahead的主要内容,如果未能解决你的问题,请参考以下文章

javascript JavaScript isset()等效: - JavaScript

JavaScript 使用JavaScript更改CSS(JavaScript)

JavaScript之基础-1 JavaScript(概述基础语法)

前端基础-JavaScript的基本概述和语法

JavaScript

JavaScript