problem with split
Eric_Dexter at msn.com
Eric_Dexter at msn.com
Sat Oct 7 02:13:46 EDT 2006
I was trying something like this
digits = re.compile("\d")
if digits in line
instr_number = digits.search(line)
because it looked realy cool when I saw it in a recent post... and then
the same thing
for just (';') didn't seem to return anything except one line and some
hex that came from god knows where./... I will see what the other does
and post the result..
hanumizzle wrote:
> On 10/7/06, goyatlah <goyatlah> wrote:
> > Think you need a regex like this: regex =
> > r"\s*instr\s+([0-9]+)\s*(;.*)?"
>
> [0-9] maybe written simply as \d (d for digit)
>
> > Then:
> > import re
> > test = re.compile(regex)
>
> Regexes are usually passed as literals directly to re.compile().
>
> > testing is done as follows:
> > res = test.match(mystring)
>
> Initial \s* is redundant if you use the search() method.
>
> > if res:
>
> I forgot that part. :)
>
> > number = res.group(1) # always a string consisting of decimals
> > comment = res.group(2) # string starting with ; or None
> > it might be necessary to have the instr part of the regex as follows
> > [iI][nN][sS][tT][rR] to handle things like Instr or INSTR.
>
> It is sufficient to use the re.IGNORECASE flag.
>
> -- Theerasak
More information about the Python-list
mailing list