problem with split

hanumizzle hanumizzle at gmail.com
Sat Oct 7 01:55:59 EDT 2006


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