In article <[EMAIL PROTECTED]>,
duikboot <[EMAIL PROTECTED]> wrote:
>
>I am trying to extract a list of strings from a text. I am looking it
>for hours now, googling didn't help either.
To emphasize the other answers you got about avoiding regexps, here's a
nice quote from my .sig database:
'Som
duikboot wrote:
> Hello,
>
> I am trying to extract a list of strings from a text. I am looking it
> for hours now, googling didn't help either.
> Could you please help me?
>
s = """
\n\n28996\n\n\n28997\n"""
regex = re.compile(r'', re.S)
L = regex.findall(s)
print L
> ['o
duikboot a écrit :
> Hello,
>
> I am trying to extract a list of strings from a text. I am looking it
> for hours now, googling didn't help either.
> Could you please help me?
>
s = """
\n\n28996\n\n\n28997\n"""
regex = re.compile(r'', re.S)
L = regex.findall(s)
print L
You're welcome!
Also, of course, parsing XML is a very common task and you might be
interested in using one of the standard modules for that, e.g.
http://docs.python.org/lib/module-xml.parsers.expat.html
Then all the tricky parsing work has been done for you.
Jason
On Sep 17, 9:31 am, duikboot
On Sep 17, 9:00 am, duikboot <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am trying to extract a list of strings from a text. I am looking it
> for hours now, googling didn't help either.
> Could you please help me?
>
> >>>s = """
> >>>\n\n28996\n\n\n28997\n"""
> >>> regex = re.compile(r'', re.S)
>
Thank you very much, it works. I guess I didn't read it right.
Arjen
On Sep 17, 3:22 pm, Jason Drew <[EMAIL PROTECTED]> wrote:
> You just need a one-character addition to your regex:
>
> regex = re.compile(r'', re.S)
>
> Note, there is now a question mark (?) after the .*
>
> By default, regular
You just need a one-character addition to your regex:
regex = re.compile(r'', re.S)
Note, there is now a question mark (?) after the .*
By default, regular expressions are "greedy" and will grab as much
text as possible when making a match. So your original expression was
grabbing everything bet