python - split by newline wildcard backslash -


split \nwildcard/. have following text:

wiring /(cid:3)(cid:9)waərŋ/ noun 1. network of wires wisdom tooth /(cid:3)(cid:9)wzdəm tu(cid:11)θ/ noun 1 of 4 teeth in of jaw witch  hazel  /(cid:3)(cid:9)wtʃ  (cid:4)hez(ə)l/ noun   lotion made    bark  of   tree 

i want split words defined, want split \n./, when use

  txt.split('\n./')  

or

  txt.split('\\n./') 

it returns txt

str.split() different re.split(). . simple dot in str.split(), not wildcard.

s = "i dogs" print(s.split('.'))   # prints ['i dogs'] 

to extract "words" like: 'wiring', 'wisdom tooth', 'witch hazel' can use regular expressions:

l = re.findall(r'(.+?)\s*/.*?\n', s) 

findall() returns list matches.

. matches non newline character, + matches 1 or more of those. () capturing group (the part of match "stored"). * means 0 or more of previous. \s whitespace character.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -