
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
JavaScript code to extract the words in quotations
Following is the code to extract the words in quotations using JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result,.sample { font-size: 20px; font-weight: 500; color: red; } </style> </head> <body> <h1>Extract the words in quotations</h1> <div style="color: green;" class="result">Hello "World"</div> <div class="sample"></div> <button class="Btn">CLICK HERE</button> <h3>Click on the above button to get the text between quotes</h3> <script> let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let sampleEle = document.querySelector(".sample"); let regex = /"(.*?)"/g; var match = regex.exec(resEle.innerHTML); BtnEle.addEventListener("click", () => { if (match) { sampleEle.innerHTML += match[0]; } }); </script> </body> </html>
Output
The above code will produce the following output −
On clicking the ‘CLICK HERE’ button −
- Related Articles
- How to extract the strings between two words in R?
- HTML Quotations
- Unique Morse Code Words in Python
- How to set the type of quotation marks for embedded quotations with JavaScript?
- How to extract words from a string vector in R?
- How to indicate long quotations in an HTML document?
- Numbers and operands to words in JavaScript
- Converting string to MORSE code in JavaScript
- How to extract the hostname portion of a URL in JavaScript?
- Extract the value of the to a variable using JavaScript?
- Calculating time taken to type words in JavaScript
- How do we extract all the words start with a vowel and length equal to n in java?
- Reversing the prime length words - JavaScript
- Python Program that extract words starting with Vowel From A list
- Code to implement bubble sort - JavaScript

Advertisements