'How to select all words at a time to apply operations at same time
Here is my sample data:
data=[1,SanjayMehra, HR, P1, Hyderabad(HYD), 01/12/1976, M],
[2,AnanyaMishra, Admin, P2,Delhi(DEL), 02/05/1968, F],
[3,RohanDiwan, Account, P3, Mumbai(BOM), 01/01/1980, M],
[4 ,SoniaKulkarni, HR, P1, Hyderabad(HYD), 02/05/1992, F],
[5, AnkitKapoor, Admin ,P2, Delhi(DEL), 03/07/1994, M]
I am trying to put inverted commas over every words here: The expected output is
data=["1", "SanjayMehra", "HR", "P1", "Hyderabad(HYD)", "01/12/1976", "M"],
["2","AnanyaMishra", "Admin", "P2", "Delhi(DEL)", "02/05/1968", "F"],
["3","RohanDiwan", "Account", "P3", "Mumbai(BOM)", "01/01/1980", "M"],
["4" ,"SoniaKulkarni", "HR", "P1", "Hyderabad(HYD)", "02/05/1992", "F"],
["5", "AnkitKapoor", "Admin" ,"P2", "Delhi(DEL)", "03/07/1994", "M"]
Right now I am putting multiple cursors using Alt+click before start and after end of each word and then pressing inverted commas in Visual studio code. With this approach I have to place it more no of times when word count increases. I am trying to find any more smarter and efficient way of achieving this through Visual studio code or programming language like Python
Solution 1:[1]
See regex101 demo.
Using this Find: (?<=\[|, |,)([^ ,\n\]]+)(?!\n)
and Replace: "$1"
It does assume that you do have commas between all the fields although your initial data was missing a couple of them.
Positive Lookbehind (?<=\[|, |,) with alternatives - where to start the matches, following a [ or , or ,
1st Capturing Group ([^ ,\n\]]+) stop at those characters: space, newline or ]
Negative Lookahead (?!\n) not followed by a newline - you might not need this if your data is simply one long input, without newlines.
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 | Mark |
