-1

I have a an array which is separated by commas, I want each word to be replaced with double quotes (for each and every word) as shown below:

a1.large,a2.large,a3.large,b4.medium

Should become:

"a1.large","a2.large","a3.large","b4.medium"

Can anyone tell how to do it in notepad++ using find and replace using regex.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Sudhakar J
  • 31
  • 3
  • 2
    Find `\w+` and replace with `"$1"` ? By the way, please clean up your sample data as it appears to have stray spaces and other formatting issues. – Tim Biegeleisen Jan 14 '22 at 04:33
  • Are there every multiple words between commas? eg `car, car keys, pepper spray, wallet`? – Bohemian Jan 14 '22 at 04:48

4 Answers4

0

Match words and replace with quoted match:

Find: \w+
Replace: "$0"

If multiple words are possible between commas, eg "car, car keys, wallet" change find regex:

Find: \w+( +\w+)*
Replace: "$0"

$0 is group zero, which is the entire match.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
0
  • Ctrl+H
  • Find what: [^,\r\n]+
  • Replace with: "$0"
  • CHECK Wrap around
  • CHECK Regular expression
  • Replace all

Explanation:

[^,\r\n]+       # 1 or more any character that is not a comma or linebreak

Replacement:

"$0"            # the whole match surrounded with quotes

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Toto
  • 89,455
  • 62
  • 89
  • 125
0

Find: [\w.]*
Replace All:"$0"

Haji Rahmatullah
  • 390
  • 1
  • 2
  • 11
-1

In notepad++, do the following:

  • CTRL + H
  • Set the Search mode:Regular Expression
  • Find (\w+(?:\s*\w+)*\s*(?=,|$))
  • Replace the matches with "$1"

Explanation:

  • \w+ - matches 1 or more word characters, as many as possible
  • (?:\s*\w+)* - matches 0 or more occurrences of 0+ spaces followed by 1+ word characters. This submattern will allow us to match multiple words separated by white-spaces between commas.
  • \s* - match 0 or more white spaces
  • (?=,|$) - positive lookahead that matches the current position if it is followed either by a , or by end of the line
  • () - everything matched so far will be captured in Group 1

Demo

enter image description here

Gurmanjot Singh
  • 10,224
  • 2
  • 19
  • 43