Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KlavierCat/1b28c75840ca8110a1f6de1fc33e9f4d to your computer and use it in GitHub Desktop.
Save KlavierCat/1b28c75840ca8110a1f6de1fc33e9f4d to your computer and use it in GitHub Desktop.
Regex for replacing formatMessage() in react-intl with t() in react-i18next

Here's a regex for replacing formatMessage() in react-intl with t() in react-i18next in the codebase. The solution here is VSCode compatible.

Strings without Arguments

  • Find: formatMessage\(messages.(\w+)\)
  • Replace: t('$1')

Strings with Arguments

  • Find:
    • formatMessage\(messages.([\w.]+)(,)(.+\)) - assuming that the keys are made up of alphanumericals and dots.
    • formatMessage\(messages.(\S+)(,)(.+\)) - a more wildcard match that allow any non empty space character in the keys.
  • Replace: t('$1'$2$3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment