Home > Blockchain >  How to take everything between 1st and 2nd comma after a newline using Regex python?
How to take everything between 1st and 2nd comma after a newline using Regex python?

Time:01-05

so I basically am reading off of a .csv file and I've already extracted the section of it that I need. The format of this part is a newline between each block of data, right now I'm trying to take the 2nd piece of info from each block. What I'm trying to do is match every newline using r"[\n]. This works but now I need to skip the first piece of data and take everything between comma 1 and 2 like this. data1, WhatIWant, data3 I've looked for a good while before posting this so sorry if I've missed a previous question with the answer but I can't find any, thanks!

CodePudding user response:

Why use specifically regex? Try using .split().

data = 'data1, WhatIWant, data3'
data_as_list = data.split(', ')
data_as_list[1] == 'WhatIWant'  # True
  •  Tags:  
  • Related