Anyone know how to modify this regex to insert a space into a UK phone number but only do it once after the 5 digits and not again at 10 digits?
msg.payload = msg.payload.replace(/(.{5})/g,'$1 ');
return msg;
thanks!
Anyone know how to modify this regex to insert a space into a UK phone number but only do it once after the 5 digits and not again at 10 digits?
msg.payload = msg.payload.replace(/(.{5})/g,'$1 ');
return msg;
thanks!
Remove the g
Definition and Usage
The "g" modifier specifies a global match.
A global match finds all matches (compared to only the first).
You could, of course, do that without a regex by splitting the string and rejoining with a space character.
thanks both!
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.