Console.log (/ (? = ^ a) bd/.test ('abd,bcd')) / / Why does false print out

I would like to ask all the bosses.
Why does console.log (/ (? = ^ a) bd/.test ("abd,bcd")) / / print out false. Maybe I don"t understand this thing well enough


look forward to find out whether
= an is followed by an and? = ^ means the beginning, so it's false

.

/ (? < = ^ a) bd/.test ('abd,bcd')

so it is true


I remember that general regular symbols match one or more characters, while these forward-looking rules match one position. Imagine that there is a cursor flashing before and after each character of the string to be matched, and these cursors are what I'm talking about.

(? = exp) matches a position that is followed by exp
(?! exp) matches a position, this position is not followed by exp
(? < = exp) matches a position, this position is preceded by exp
(? .

(? = ^ a) bd means:
first matches a cursor position, which must be followed by a string followed by a
followed by bd

.

so there is a contradiction here. There can never be a string that satisfies this regularity. A position is followed by ^ an and bd.

vice versa bd (? = a) is right, matching db is followed by a position, which must be followed by a.
(? < = ^ a) bd also explains that it matches a position that must be preceded by the beginning + a, followed by bd.

is this analysis easy to understand? You don't have to remember whether the parentheses are put before or after. Remember that they match a cursor position on OK. This is what the zero width assertion means that they match a cursor position without length. Haha

Menu