ScrapVim-lite-2/wordSplitter
文字列を単語に分割する関数
21:12:16 前に動くやつと後ろに動くやつで空白の扱いが異なるようだ
we
単語の末尾に空白を含める
bge
単語の先頭に空白を含める
文字列を単語単位で区切る
使いやすいようにpropertiesを変える
code:script.js
export function splitWords(text) {
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) {
return [...text.matchAll(/(?:\S+|\s)^\S\n*\n*/ug)] .map(match => {return {word: match0, index: match.index, length: match0.length}}); }