Fredrik Lundh wrote:
> John Henry wrote:
>
> > Oops!
>
> for cases like this, writing
>
> "[" + re.escape(charset) + "]"
>
So, like this?
newString= re.split("[" + re.escape("; ()[]") + "]", result)
> is usually a good way to avoid repeated oops:ing.
>
> > newString= re.split("[; ()\[\]"
John Henry wrote:
> Oops!
for cases like this, writing
"[" + re.escape(charset) + "]"
is usually a good way to avoid repeated oops:ing.
> newString= re.split("[; ()\[\]", result)
>>> newString= re.split("[; ()\[\]", result)
Traceback (most recent call last):
...
sre_constants.er
Oops!
newString= re.split("[; ()\[\]", result)
John Henry wrote:
> Meaning:
>
> import re
>
> newString= re.split('[; ()\[\]", result)
>
>
>
> Nick Vatamaniuc wrote:
> > The regular string split does not take a _class_ of characters as the
> > separator, it only takes one separator. Your example
Meaning:
import re
newString= re.split('[; ()\[\]", result)
Nick Vatamaniuc wrote:
> The regular string split does not take a _class_ of characters as the
> separator, it only takes one separator. Your example suggests that you
> expect that _any_ of the characters "; ()[]" could be a separato
"ronrsr" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm trying to break up the result tuple into keyword phrases. The
> keyword phrases are separated by a ; -- the split function is not
> working the way I believe it should be. Can anyone see what I"m doing
> wrong?
>
> bests,
"ronrsr" <[EMAIL PROTECTED]> wrote:
> I'm trying to break up the result tuple into keyword phrases. The
> keyword phrases are separated by a ; -- the split function is not
> working the way I believe it should be. Can anyone see what I"m doing
> wrong?
I think your example boils down to:
>>> h
ronrsr wrote:
> I'm trying to break up the result tuple into keyword phrases. The
> keyword phrases are separated by a ; -- the split function is not
> working the way I believe it should be.
>>> help(str.split)
split(...)
S.split([sep [,maxsplit]]) -> list of strings
Return a lis
The regular string split does not take a _class_ of characters as the
separator, it only takes one separator. Your example suggests that you
expect that _any_ of the characters "; ()[]" could be a separator.
If you want to use a regular expression as a list of separators, then
you need to use the s