问题
I am using regex in javascript and want to replace all the digits in a number except the last four with '#'. I have figured out how to replace all the digits with '#', what do I do to not replace the last four? Here is my code so far. return cc.replace(/[0-9]/g, "#")
回答1:
use this pattern
\d(?=\d{4})
and replace with #
Demo
来源:https://stackoverflow.com/questions/35509964/replace-all-digits-except-the-last-four-using-regex