export function getImgUrl(content) {
let matchReg = /<img.*?(?:>|\/>)/gi;
let arr2 = content.match(matchReg);
let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
let imgUrl = "";
if (arr2 != null) {
let src = arr2[0].match(srcReg);
imgUrl = src[1];
}
return imgUrl;
}
export function getText(str) {
let words = str.replace(/ /gi, "");
return words;
}
export function clearRichText(texts) {
let text1 = texts.replace(/<\/?(img|table)[^>]*>/g, "");
let text2 = text1.replace(/<\/?.+?>/g, "");
let text3 = text2.replace(/[ | ]*\n/g, "\n");
let text4 = text3.replace(/ /g, "");
return text4;
}
export function getVideo(str) {
const regex = /<video.*?src=["']([^"']+)["']/g;
const videoTags = str.match(regex);
const videoUrls = [];
if (videoTags) {
for (let i = 0; i < videoTags.length; i++) {
const match = regex.exec(videoTags[i]);
if (match) {
videoUrls.push(match[1]);
}
}
}
return videoUrls[0];
}