ScrapVim-lite-2/wordSplitter
文字列を単語に分割する関数
ScrapVim-lite-2で使う
from ScrapVim-lite#5fb92f4a1280f00000aa09c7
21:12:16 前に動くやつと後ろに動くやつで空白の扱いが異なるようだ
we
単語の末尾に空白を含める
bge
単語の先頭に空白を含める
文字列を単語単位で区切る
使いやすいようにpropertiesを変える
code:script.js
export function splitWords(text) {
if (text === '') return {word: '', index: 0, length: 0};
return [...text.matchAll(/(?:\p{sc=Hira}+|ヲ-゚+|ァ-ヶ+|\p{sc=Han}+|\p{sc=Latin}+|0-9+|0-9+|.)^\S\n*\n*/ug)]
.map(match => {return {word: match0, index: match.index, length: match0.length}});
}
文字列を空白文字で区切る
code:script.js
export function splitWORDs(text) {
if (text === '') return {word: '', index: 0, length: 0};
return [...text.matchAll(/(?:\S+|\s)^\S\n*\n*/ug)]
.map(match => {return {word: match0, index: match.index, length: match0.length}});
}
#2020-11-24 17:39:29