Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a space after the 4th and 10th character [duplicate]

I have a string consisting of 15 digits. For example, 347405405655278. I need to add a blank space after the 4th digit and then after the 10th digit making it look like 3474 054056 55278. Can I achieve this using a regular expression?

like image 202
Zameer Khan Avatar asked Apr 29 '14 12:04

Zameer Khan


1 Answers

With the help of regular expression, you can use the given below code to achieve the desired result:

var result = "347405405655278".replace(/^(.{4})(.{6})(.*)$/, "$1 $2 $3");
like image 175
Vikash Dwivedi Avatar answered Sep 30 '22 17:09

Vikash Dwivedi