Regular Expressions 101

[React TypeScript] Unnecessary brackets around strings

Open Workspace
  • JavaScript
  • Substitution
1

Regular Expression

/
(\w+\s*\n*=\s*\n*)\{\n*\s*("([^"]*)"|'([^']*)')\n*\s*\}
/
gm

Description

Matches string properties that unnecessarily use brackets in React components.

NOTE: If you're looking to harmonise your quote usage, use this substitution input: $1"$3$4"

But be aware that strings that use single quotes inside double quotes or vice-versa will break!!!

Submitted by Nathanthanthan