you'd better give the original content source. Refer to
. If you follow the above explanation, you will not know the relationship between this and
.
var re = /quicks(brown).*(jumps)/ig;
The difference between
.
the. + here? It should mean lazy matching.
=
confirmed, which means lazy match
here. +? It means to match at least 1 arbitrary character and take as few characters as possible.
such as
var re0 = /quick\s(brown).+?(jumps)/ig;
var re1 = /quick\s(brown).+(jumps)/ig;
var result01 = re0.exec('The Quick BrownJumps Fox Jumps Over The Lazy Dog'); // Quick BrownJumps Fox Jumps Quick BrownJumpsBrownJumps.+
re0.lastIndex=0;
var result02 = re0.exec('The Quick Brown Fox Jumps Over The Lazy Dog');// Quick Brown Fox Jumps
re0.lastIndex=0;
var result03 = re0.exec('The Quick Brown Jumps Fox Jumps Over The Lazy Dog');// The Quick Brown Jumps Quick Brown Jumps Fox Jumps
var result11 = re1.exec('The Quick BrownJumps Fox Jumps Over The Lazy Dog');// Quick BrownJumps Fox Jumps Quick BrownJumps Quick BrownJumps .+
re1.lastIndex=0;
var result12 = re1.exec('The Quick Brown Fox Jumps Over The Lazy Dog');// The Quick Brown Fox Jumps
re1.lastIndex=0;
var result13 = re1.exec('The Quick Brown Jumps Fox Jumps Over The Lazy Dog');// The Quick Brown Jumps Fox Jumps Quick Brown Jumps
console.log(result01);
console.log(result02);
console.log(result03);
console.log(result11);
console.log(result12);
console.log(result13);
just take a look at the test results.
. +? Say hello, followed by. +, which means the preceding. + combination (any character) is optional.
Let me force a wave of your rules, according to my personal understanding.
quicks, there is nothing to say but match quicks
(brown). What it means is: brown is followed by any character, which is called a
(brown). + for convenience, which means that there is at least one a, and there can be more than one. It is called b
(brown). + for convenience. It means that a match can be satisfied with a b or no b.
as for the last (jumps), it is jumps
I: ignore case
g: global match
to sum up: the string that satisfies the match must first have a quicks, then a b or no b, and finally a jumps
.