You are not logged in.

#1 2005-06-09 07:55:22

giddygiddyBA
Member
From: Montreal
Registered: 2004-12-30
Posts: 66

splitting strings with python

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*.   

sometime the (1) and (2) are not included - they are included only if the word has two different meanings


"..." means that there are some times 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,

.

Offline

#2 2005-06-09 08:12:29

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,615
Website

Re: splitting strings with python

Try breaking down your problem first.
First, check to see if the string include (1) or (2), then act accordingly on those logical branch conditions..


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#3 2005-06-09 15:17:27

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: splitting strings with python

I would do it case-by-case, as it would get too complicated otherwise...
use re.search(pattern).groups to get the matches

Offline

#4 2005-06-10 14:03:01

giddygiddyBA
Member
From: Montreal
Registered: 2004-12-30
Posts: 66

Re: splitting strings with python

thanks for the help.

Im impressed how well python handles unicode characters, it wasnt so hard to do after all!

Offline

Board footer

Powered by FluxBB