alexa

Extract Clickable words from String and Include Punctuation Marks in nods.js ?

Extract Clickable words from String and Include Punctuation Marks in nods.js ?

I think that using RegExp would make your life easier:

 

 const content = `Into the trunk we put two poles and the can of worms and a sack of sandwiches and a thermos of water. "We're going on a journey," my father said. "To a secret place. We'll catch the air! We'll catch the breeze!`;
const result = content.match(/([\w'])+|([\.;,:-_?!"]+[\s"]*["]*)/gim);
console.log(result);
const punctuation = /[\.;,:\-_?!"]+/;

 function App() {
    return (
    <div>
      {result.map((w) =>
        punctuation.test(w) ? w : <a href={`/word/${w}`}>{w + '\n'}</a>
      )}
    </div>
  );
}

ReactDOM.render(<App/>, document.getElementById("root"))
 <div id="root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

193 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online

Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry