https://wiki.cabal.mx/index.php?title=Curso_de_Programaci%C3%B3n_en_Python/RegEx-13&feed=atom&action=historyCurso de Programación en Python/RegEx-13 - Historial de revisiones2024-03-29T10:30:34ZHistorial de revisiones para esta página en el wikiMediaWiki 1.32.1https://wiki.cabal.mx/index.php?title=Curso_de_Programaci%C3%B3n_en_Python/RegEx-13&diff=119483&oldid=prevRrc en 14:18 18 dic 20152015-12-18T14:18:01Z<p></p>
<p><b>Página nueva</b></p><div>= Más back reference por posición =<br />
<br />
<pre><br />
tenemos un archivo con etiquetas:<br />
[rrc@Pridd ~]$ cat Etiquetas.xml <br />
<br />
<composer>Wolfgang Amadeus Mozart</composer><br />
<author>Orson Scott Card</author><br />
<city>Guadalajara</city><br />
<maestro>Richard Couture</maestro><br />
<br />
que quieremos presentar en la forma:<br />
Etiqueta: Valor<br />
<br />
Python 3.4.3 (default, Jul 1 2015, 18:38:11) <br />
[GCC 4.9.2] on linux<br />
Type "help", "copyright", "credits" or "license" for more information.<br />
>>> import re<br />
>>> fh = open("Etiquetas.xml")<br />
>>> for i in fh:<br />
... res = re.search(r"<([a-z]+)>(.*)</\1>",i)<br />
... print(res.group(1) + ": " + res.group(2))<br />
... <br />
composer: Wolfgang Amadeus Mozart<br />
author: Orson Scott Card<br />
city: Guadalajara<br />
maestro: Richard Couture<br />
>>></div>Rrc