'Regex to enclose objects in an array
I have lots of files containing many calls to a specific method which used to accept objects but now requires an array. I would like to use Notepad++ to find/replace all of these calls with the required array.
Here's an example:
attach({ name: 'filename', url: 'fileURL' })
This needs to be converted to:
attach([{ name: 'filename', url: 'fileURL' }])
Any help with this would be much appreciated.
Solution 1:[1]
I'd search for:
attach\((.+)\)
and replace it with
attach([$1])
This will capture everything between attach's parentheses and adds a pair of square brackets around it.
edit: Older versions of notepad++ use \1 instead of $1 to refer to the 1st captured group.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
