python - split by newline wildcard backslash -
split \n
wildcard/
. have following text:
wiring /(cid:3)(cid:9)waərŋ/ noun 1. network of wires wisdom tooth /(cid:3)(cid:9)wzdəm tu(cid:11)θ/ noun 1 of 4 teeth in of jaw witch hazel /(cid:3)(cid:9)wtʃ (cid:4)hez(ə)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
Post a Comment