Regular/摘取匹配词附近:修订间差异
来自康健生活
| 第9行: | 第9行: | ||
<blockquote><pre> | <blockquote><pre> | ||
取预处理的嵌入物并在张力板上进行大大可视化。 嵌入->训练嵌入 metadata.tsv->元数据信息 最大大</pre></blockquote> | 取预处理的嵌入物并在张力板上进行大大可视化。 嵌入->训练嵌入 metadata.tsv->元数据信息 最大大</pre></blockquote> | ||
进一步处理: | |||
<syntaxhighlight lang="javascript"> | |||
export function textRegular (text, key) { | |||
if (text && text.length > 1) { | |||
const pattern = '.{1,5}(?=(' + key + ')).{1,50}(?<!(' + key + '))' | |||
const reg = new RegExp(pattern, 'ig') | |||
const getTextArray = text.match(reg) | |||
// eslint-disable-next-line no-unused-vars | |||
let getFirstText | |||
// eslint-disable-next-line no-constant-condition | |||
if (getTextArray !== null) { | |||
getFirstText = getTextArray[0] | |||
// getFirstText = getFirstText.replace(new RegExp(key, 'ig'), '<span class=textLight >$&' + '</span >') | |||
} else { | |||
getFirstText = text.slice(0, 30) | |||
} | |||
return getFirstText | |||
} else { | |||
return text | |||
} | |||
}</syntaxhighlight> | |||