<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
thanks very much Stuart for your explanation. Kind of you <br><br><div>> Date: Sun, 2 Oct 2011 16:22:05 +0100<br>> From: stuart@sjsears.com<br>> To: gllug@gllug.org.uk<br>> Subject: Re: [Gllug] matching strings in python<br>> <br>> On 02/10/2011 11:08, dudes dudes wrote:<br>> ><br>> ><br>> >  ><br>> >  > RTFM :)<br>> ><br>> > TFM has been Read b4 starting the project :P<br>> <br>> well, that's very good. Did you go back to it when your pattern wasn't <br>> working?<br>> <br>> >  > http://docs.python.org/library/re.html#matching-vs-searching<br>> >  ><br>> >  > specifically:<br>> >  > where are these numbers on each line? Are they at the start? if not,<br>> >  > re.match won't find them without a preceding wildcard.<br>> ><br>> > yes there are one each line and at the start of each<br>> <br>> so your pattern can be simpler.<br>> <br>> >  > Also, there's no need for the 'this=...' bit, unless you actually feel<br>> >  > you need the variable.<br>> ><br>> > yes I need "this" as variable even though it has a different variable<br>> > name in the source code.<br>> ><br>> >  > Something like the following<br>> >  ><br>> >  > for line in open('filename'):<br>> >  > if re.search('1000[01]', line):<br>> >  > print line<br>> ><br>> ><br>> >  > is more likely to succeed<br>> ><br>> > YES True, but there are 10.000 different digit numbers, but I only need<br>> > to find 10 numbers .. such as 10000, 10001, 1286, 3412, 3512, 456,<br>> > 653,,,etc and they are different. Therefore I need to retrieve one out<br>> > of these 10 numbers !<br>> <br>> The regex pattern I gave you matches '10000' and '10001', which was all <br>> you asked for.<br>> Your response above sort-of suggests that you don't realise this?<br>> <br>> It would be fairly trivial to extend it to match all the numbers you <br>> want. Something like...<br>> <br>> re.match('^(1000[01]|653|1286|...)', line)<br>> <br>> (this time being specific that the numbers are at the beginning of each <br>> line.)<br>> <br>> another point: how many lines are there in the file?<br>> For more than a small number it is arguably more efficient to do this:<br>> <br>> numpatt = re.compile(PATTERN)<br>> for line in this:<br>>      if numpatt.match(line):<br>>          print line<br>> <br>> Or you essentially re-run the re.compile process for every line.<br>> <br>> [snip]<br>> > yes True but using DrPython as an editor won't let you to save the code<br>> > if you have syntax issues.<br>> <br>> We don't know that.<br>> <br>> >  > This example was fairly trivial, but if you are asking for help with<br>> >  > code like this, it would help if you actually post working excerpts from<br>> >  > it. Or excerpts that throw the errors you are asking about.<br>> ><br>> > agree and thank you :)<br>> <br>> Regards,<br>> <br>> Stuart<br>> -- <br>> Stuart Sears RHCA etc.<br>> "It's today!" said Piglet.<br>> "My favourite day," said Pooh.<br>> --<br>> Gllug mailing list  -  Gllug@gllug.org.uk<br>> http://lists.gllug.org.uk/mailman/listinfo/gllug<br></div>                                    </div></body>
</html>