In a section of Sevelte tutorial, there’s a piece of code like this:
view = pin ? pin.replace(/\d(?!$)/g, '•') : 'enter your pin';
I know \d means a digit, but can’t figure out what (?!$) means.
(And because it’s composed of all punctuation, I can’t manage to google for an explanation.)
Please help, thanks.
>Solution :
\dmatches all digits?!means ‘Negative Lookahead’$matches the end of a string
So when \d(?!$) is used, it matches all digits before the last character
In this string:
$$//www12.example@news.com<~>998123000dasas00–987
This will be matched (7 will not because it is the last character):
129981230000098
Referred to this answer
and Regex Cheat Sheet