Home > Software design >  Python- Regex or other method to get specific words
Python- Regex or other method to get specific words

Time:12-19

I need a way to put the "column" names in a list, using regex or other method in python.

.create table ['IIQStatusContaInfo'] ingestion json mapping 'IIQStatusContaInfo_mapping' '[{"column":"DataColetaConta", "Properties":{"Path":"$['DataColetaConta']"}},{"column":"Chave", "Properties":{"Path":"$['Chave']"}},{"column":"CodBIRH", "Properties":{"Path":"$['CodBIRH']"}},{"column":"NomeConta", "Properties":{"Path":"$['NomeConta']"}},{"column":"StatusRecurso", "Properties":{"Path":"$['StatusRecurso']"}},{"column":"IdentidadeAtivo", "Properties":{"Path":"$['IdentidadeAtivo']"}},{"column":"SituacaoBIRH", "Properties":{"Path":"$['SituacaoBIRH']"}},{"column":"DataColeta", "Properties":{"Path":"$['DataColeta']"}}]'

Output it has to be something like this:

['DataColetaConta', 'Chave', 'CodBIRH', 'NomeConta', ...]

CodePudding user response:

import re

txt = ".create table [\'IIQStatusContaInfo\'] ingestion json mapping \'IIQStatusContaInfo_mapping\' \'[{\"column\":\"DataColetaConta\", \"Properties\":{\"Path\":\"$[\'DataColetaConta\']\"}},{\"column\":\"Chave\", \"Properties\":{\"Path\":\"$[\'Chave\']\"}},{\"column\":\"CodBIRH\", \"Properties\":{\"Path\":\"$[\'CodBIRH\']\"}},{\"column\":\"NomeConta\", \"Properties\":{\"Path\":\"$[\'NomeConta\']\"}},{\"column\":\"StatusRecurso\", \"Properties\":{\"Path\":\"$[\'StatusRecurso\']\"}},{\"column\":\"IdentidadeAtivo\", \"Properties\":{\"Path\":\"$[\'IdentidadeAtivo\']\"}},{\"column\":\"SituacaoBIRH\", \"Properties\":{\"Path\":\"$[\'SituacaoBIRH\']\"}},{\"column\":\"DataColeta\", \"Properties\":{\"Path\":\"$[\'DataColeta\']\"}}]\'"
x = re.findall("\"column\"\:\"(. ?)\"", txt)

print(x)
  • Related