I want to find a specific two words in a string id
and name
, I think use Regular Expressions, but I can not format.
In file I have:
<p>Any text, bla bla lorem ipsum, bla bla</p>
<p>test = {"player":{"id":"123123","name":"f_teste"};
Here is my progress:
import re
def main():
padrao = r'"id"\w+'
caminho = 'D:\index.txt'
arquivo = open(caminho,'r')
texto = arquivo.readlines()[1].split('{')
textoEncontrado = texto[2].split(',')
print textoEncontrado[0]
print textoEncontrado[1]
arquivo.close()
if __name__ == '__main__':
main()
Result:
"id":"123123"
"name":"f_teste"};
What I want:
id: 123123
name = f_teste
When I try get only string id
using RE, I got:
padrao = r'^id$'
(...)
result = re.findall(padrao,textoEncontrado[0])
print result
(...)
Result is []
Sorry for bad english.
Thanks all. :)