正则表达式相关实战

110 阅读1分钟

对指定字符串,从前往后每3位增加一个逗号“,”

示例: 指定"123456789"字符串,替换为"123,456,789"

const result = "123456789".replace(/(?<=^(\d{3})+)(?!$)/g, ',')