splitting strings with python

inhahe iseestars at gate.net
Thu Jun 9 06:17:38 EDT 2005


<sbucking at gmail.com> wrote in message
news:1118308380.823382.146430 at g47g2000cwa.googlegroups.com...
> im trying to split a string with this form (the string is from a
> japanese dictionary file with mulitple definitions in english for each
> japanese word)
>
>
> str1 [str2] / (def1, ...) (1) def2 / def3 / .... (2) def4/ def5 ... /
>
>
> the varibles i need are str*, def*.
>
> sometimes the (1) and (2) are not included - they are included only if
> the word has two different meanings
>
>
> "..." means that there are sometimes more then two definitions per
> meaning.
>
>
> im trying to use the re.split() function but with no luck.
>
> Is this possible with python, or am i dreamin!?
>
> All the best,
>
> .
>

i don't think you can do it with string.split, although i guess you could do
it with re.split, although i think it's easier to use re.findall.

import re
re.findall("[a-zA-Z][ a-zA-Z0-9]*", inputstring)

should work.







More information about the Python-list mailing list