[python-nl] Python-nl Digest, Vol 68, Issue 12 Module -re

Hendrikus Godvliet hendrikusgodvliet at gmail.com
Tue Jan 26 12:36:12 CET 2010


Message: 1
> Date: Tue, 26 Jan 2010 11:33:23 +0100
> From: Wichert Akkerman <wichert op wiggy.net>
> To: python-nl op python.org
> Subject: Re: [python-nl] Python-nl Digest, Vol 68, Issue 10
> Message-ID: <4B5EC4F3.40208 op wiggy.net>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 1/26/10 11:31 , Hendrikus Godvliet wrote:
> > Hallo Allemaal:
> >
> > Van de Django meeting naar iets anders de Python module re
> >
> > In v.b den vindt ik geen antwoord hoe je de module re toepast op een
> > file / bestand.
> >
> >>>>  import re
> >>>>  search_me ="my phone number is 917-555-1234 hey hey"
> >
> >>>>  match_obj = re.search(r"(\d{3})-(\d{3})-(\d{4})", search_me)
> >
> > Ik zoek naar |zoiets als
> > f = open("test.dat", "r")|
> >
> >>>>  import re
> >>>>  search_me =|  open("test.dat","r")|
> >
> > Graag hier een aanwijzing in?
>
> python gebruikt geen magische operators. Maar je kan het heel makkelijk
> gewoon uitschrijven:
>
>   search_me = open("test.dat").read()
>   match_obj = re.search(r"(\d{3})-(\d{3})-(\d{4})", search_me)
>
> Wichert.
>
>
Wichert

Dank voor je hulp - aanwijzing. Waarom het bij niet werkte was omdat ik
.read() niet had toegevoegd.

import re

text = open("datum", "r")*.read()*

m = re.match("(\d{2})/(\d{2})/(\d{2,4})", text)
if m:
    print m.group(1, 2, 3)


Groet Hendrikus Godvliet
------------- volgend deel ------------
Een HTML-bijlage is gescrubt...
URL: <http://mail.python.org/pipermail/python-nl/attachments/20100126/0aa3eec1/attachment.htm>


More information about the Python-nl mailing list