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
CodePudding user response:
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.
CodePudding user response:
if you are saying that you want to select all words from this database so use regular expressions. you should use * of regular expressions. you have to import re and turn this database into a variable and then use re.match('*', variable_of_database)