regex for formatting NZ numbers
devides a given string of numbers. work with php, js, python
(0800) 123 123 format
023123123 -> (02) 322 3123
0123123123 -> (012) 312 3123
02123123123 -> (0212) 312 3123
/(0800|\d*?)(\d{3})(\d{4}|\d{3})$/| // js example | |
| const regex = /(0800|\d*?)(\d{3})(\d{4}|\d{3})$/g; | |
| const str = `0800123123`; | |
| const subst = `(\$1) \$2 \$3`; | |
| const result = str.replace(regex, subst); | |
| // result = (0800) 123 123 |
| <?php | |
| // php example | |
| $re = '/(0800|\d*?)(\d{3})(\d{4}|\d{3})$/'; | |
| $str = '0800123123'; | |
| $subst = '($1) $2 $3'; | |
| $result = preg_replace($re, $subst, $str); | |
| // $result = (0800) 123 123 |