You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a solution possible with format phone number using regexes and replacing groups. So whatever you put inside brackets, you can then reference in the replace clause using $1$2 and so on.
There is a solution possible with format phone number using regexes and replacing groups. So whatever you put inside brackets, you can then reference in the replace clause using
$1
$2
and so on.Here is the code:
So I am first converting the numbers array into string using
reduce
.Then I am creating regex groups in the left side of
replace
statement:([0-9]{3})
means first 3 digits will be accessible via$1
([0-9]{3})
means next 3 digits will be accessible via$2
([0-9]{3})
means last 4 digits will be accessible via$3
Then you can reference it in the right side of
replace
statement using($1) $2-$3
.The text was updated successfully, but these errors were encountered: