Regular Expressions (RegEx) → How to take a text list and surround each line in quotes

The Problem

If you have a list from a text file such as this:


And you want this, let’s say for an array:


The Solution

You need to use a find and replace in your IDE (I’m using PHPStorm). Enable the ability to RegEx in your Find & Replace.

Then for your find:


And your replace:


This will select all the word for you and add the quotes and the comma. The $1 is a RegEx variable that has a value of the results it found. $1 means the first result from your RegEx search.

Hope this helps

Happy Coding!

Like what you read? Give Tony Mucci a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.