screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script> <script src="https://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> function App() { // Regular expression to match URLs const text = "Visit Google at https://www.google.com. " + "Connect with friends on Facebook at https://www.facebook.com. " + "Network with professionals on LinkedIn at https://www.linkedin.com. " + "Explore ChatGPT at https://www.chatgpt.com. " + "Shop for electronics at https://www.amazon.com. " + "Get the latest fashion trends at https://www.zara.com. " + "Discover world news at https://www.bbc.com. " + "Learn about space exploration at https://www.nasa.gov."; const urlRegex = /(https?:\/\/[^\s]+)/g; // Split the text into parts containing URLs and other text const parts = text.split(urlRegex); // Map the parts to create a mixed array of text and links const formattedText = parts.map((part, index) => { if (part.match(urlRegex)) { // If the part is a URL, convert it to a clickable link return ( <a key={index} href={part} target="_blank" rel="noopener noreferrer"> {part} </a> ); } else { // If it's regular text, just display it as-is return <span key={index}>{part}</span>; } }); return ( <div className='container'> <h3>React Js Detect URLs in Text and Convert to link</h3> {formattedText} </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { font-family: Arial, sans-serif; padding: 20px; border-radius: 5px; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2); max-width: 600px; margin: 0 auto; text-align: center; } h3 { color: #333; } a { color: #007bff; text-decoration: none; font-weight: bold; } a:hover { text-decoration: underline; } span { color: #333; } </style> </body> </html>