Skip to content

Instantly share code, notes, and snippets.

@scajanus
Created January 13, 2015 09:00
Show Gist options
  • Select an option

  • Save scajanus/1713c1a3d3ceba3df16d to your computer and use it in GitHub Desktop.

Select an option

Save scajanus/1713c1a3d3ceba3df16d to your computer and use it in GitHub Desktop.
Regex stuff
import re
line="<td>id=j_i dt133_j_idt134_j_idt188_j_idt189_uitwc_0_uitwc_0_U20</td> muotoon <td>css=[id$=U20]</td>"
#pitää siis tunnistaa rivit joissa tuo id:n sisältö loppuu johonkin U-alkuiseen stringiin ja siirtää se U-osuus tuohon uuteen muotoon.
m = re.search("id\=[\w_]*_(U\w*)</td>",line)
try:
print m.group(1)
line2 = "<td>css=[id$="
line2 +=m.group(1)
line2 +="]</td>"
print (line2)
except:
print "match not found"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment