highlight the word at content

  // highlitingall but getting error at ist plural

// highlightContent(content, keywords) {
// console.log(content);
// const regexPattern = keywords
// .map(keyword => {
// const escapedKeyword = keyword.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
// return `\\b${escapedKeyword}(?:(?:'s|s\\b|'\\bs)\\b(?!\\s*[a-z]))?`;
// })
// .join('|');
// const regex = new RegExp(regexPattern, 'gi');
// const highlightedContent = content.replace(regex, match => `<span class="highlight">${match}</span>`);
// console.log(highlightedContent);
// return highlightedContent;
// },
// return `\\b${escapedKeyword}\\b`;
highlightContent(content, keywords) {
const regexPattern = keywords
.map(keyword => {
const escapedKeyword = keyword.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
return `\\b${escapedKeyword}(?:(?:'s|'\\bs)\\b(?!\\s*[a-z]))?`;
})
.join('|');
const regex = new RegExp(regexPattern, 'gi');
const highlightedContent = content.replace(regex, match => `<span class="highlight">${match}</span>`);
return highlightedContent;
},

1 comment:

  1. // const isIdInArray = this.get_competitor_subscriptions.some(item => item.item === this.defaults.competitor_subscription_id);
    // if (!isIdInArray) {
    // this.defaults.competitor_subscription_id="";
    // }

    ReplyDelete

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...