正規表現をセパレータとして使用して文字列を分割しようとしましたが、の出力にはstring.split
冗長な結果が含まれているようです。
import re;
replaceArray = '((Replace the string)|((in|inside|within) the string)|(with the string))'
stringToSplit = '(Replace the string arr1 in the array arr2 with the array arr3)'
print(re.split(replaceArray, stringToSplit))
結果が重複することなく、分割文字列が次のようになると予想しました。
['Replace the string', ' arr1 ', 'in the string', ' arr2 ', 'with the string', ' arr3']
しかし代わりに、分割された文字列の配列には冗長な結果が含まれており、一致した他の文字列と重複しているように見えます。
['', 'Replace the string', 'Replace the string', None, None, None, ' arr1 ', 'in the string', None, 'in the string', 'in', None, ' arr2 ', 'with the string', None, None, None, 'with the string', ' arr3']
これらの冗長で重複する結果が の出力に含まれないようにする方法はありますstring.split
か?