I'd like to ask you about the principle of this regularity.

/^(?:\/(?=$))?$/

this rule is used to match the

of an empty string.
"".match(/^(?:\/(?=$))?$/)
 ["", index: 0, input: "", groups: undefined]

"1".match(/^(?:\/(?=$))?$/)
 null

? = I know this is an antecedent assertion, which means that it must be followed by $.
but I don"t understand how the whole regular match is empty. (? = $) it has been defined that it must be followed by $, so if there is at least $, how can it be empty?


matches a blank row or data with only / in a row
such as:
Click to view


(? =) will be used as a matching check, but will not appear in the matching result string

(?:) is used as a match check and appears in the matching result character. It differs from (.) in that it is not returned as a child match.

var data = 'windows 98 is ok';
data.match(/windows (?=\d+)/);  // ["windows "]
data.match(/windows (?:\d+)/);  // ["windows 98"]
data.match(/windows (\d+)/);    // ["windows 98", "98"]
Menu