Regexp - formating french telephone numbers

Describe the problem/error/question

Hi Community,
I’m not a big fan of regexp, but I understand it is very powerful.
I’m trying to format french telephon numbers.
Final format should be +33999999999

This expression (almost) works
{{$json["Téléphone"].replace(/^(?:\+?33|0)?(?:[ .-]?)(\d{9})$/, '+33$1')}}

When input is 33999999999, return should be +33999999999, however, with the regexp above, it returns an empty string

What is the error message (if any)?

no error

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.55.3
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: Windows 11

hello @hsteph

Actually, it’s easier to avoid regex, as it’s too complicated to work with and debug.
You can achieve a cleaner solution with Code node and formatting the phone in multiple steps

2 Likes

Thanks,
So, I’m not the only thinking that regex is a monster ?
:wink:

It’s quite useful in certain circumstances, but if there are other ways, better to use them and leave the regex as a last resort

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.