最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Replace all digits except the last four using regex. - Stack Overflow

programmeradmin0浏览0评论

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, "#")

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, "#")

Share Improve this question asked Feb 19, 2016 at 16:21 AaronAaron 4,48021 gold badges92 silver badges150 bronze badges 2
  • Is the string of a specific size? – acupofjose Commented Feb 19, 2016 at 16:24
  • 2 What if there are less than 4 digits? – Oriol Commented Feb 19, 2016 at 16:26
Add a comment  | 

1 Answer 1

Reset to default 18

use this pattern

\d(?=\d{4})

and replace with #
Demo

发布评论

评论列表(0)

  1. 暂无评论