Search code examples
regexwebstorm

WebStorm use Regex to add quotations around found matches


Given the following array:

R991,U847,L239,U883,L224,D359,L907,D944,L79,U265,L107

I'd like to add quotation around each individual instance of a letter followed by a number of characters using the 'search and replace' function.

Now in the search function I can target all the instances using the Regex option, and using [A-Z]\d*.

Now for the replace value, how can I use a certain wildcard character to keep the same Regex value intact?

Example:

enter image description here

The end result should be:

"R991","U847","L239","U883","L224","D359","L907","D944","L79","U265","L107"

Note: As a quick fix I searched for each , and replaced that with "," which almost fixed it entirely. But I'm wondering for more complex cases you could use a wildcard.


Solution

  • Search for: ([A-Z]\d+)
    Replace by: "$1"

    enter image description here

    https://www.jetbrains.com/help/webstorm/tutorial-finding-and-replacing-text-using-regular-expressions.html#capture_groups_and_backreference