JavaScript/regex: Remove text between brackets in string [duplicate] - javascript

This question already has answers here:
How to strip HTML tags from string in JavaScript? [duplicate]
(4 answers)
Closed 2 years ago.
How would I remove all <> tags from a string, and the contents within them?
<p>Hello, how are you doing <strong>today</strong></p>
to
Hello, how are you doing today
using JavaScript with Regex?

Here is how you can do it:
const input = '<p>Hello, how are you doing <strong>today</strong></p>';
const result = input.replace(/<[^>]+>/g, '');
console.log(result);

Related

How i can use variable in string? [duplicate]

This question already has answers here:
Template literals like 'some ${string}' or "some ${string}" are not working
(7 answers)
Closed 1 year ago.
I have problem with template strings. I created a variable, but i can't put it in string
let suffix = "-dev";
alert("hello, ${suffix}");
To use template strings you have to use backticks ( `` ).
let suffix = "-dev";
alert(`hello, ${suffix}`);

I need How to split this string in javascript? [duplicate]

This question already has answers here:
Regular Expression to find a string included between two characters while EXCLUDING the delimiters
(13 answers)
Closed 5 years ago.
var faxNum = $("#txt_faxnum").val();
//Value : ""kekurt kekt809" <(732) 588-8300>"
I want to split between "< >". Example: Just I need to this section : (732) 588-8300
How to split this string ?
You can try this
var String=faxNum.substring(str.lastIndexOf("<")+1,faxNum.lastIndexOf(">"));

Regex to match period(.) following by only at the end of html string [duplicate]

This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 5 years ago.
How do I match the . in the following html string.
<p>My first <strong>comment</strong>. </p>
The above string could have more than one at the end before the closing paragraph tag.
Try with /\.(?: )+(?=[^.]*$)/g.
var str = '<p>. My first <strong>comment</strong>. </p>';
console.log(str.replace(/\.(?: )+(?=[^.]*$)/g, 'test'));
//"<p>. My first <strong>comment</strong>test</p>"

Javascript remove commas from string [duplicate]

This question already has answers here:
Remove characters from a string [duplicate]
(6 answers)
Closed 7 years ago.
I have the below variable in JavaScript. I want to remove the "comma" sign using jQuery /JavaScript.
var test = ",,2,4,,,3,,3,,,"
Expected output: var test = "2,4,3,3"
please advice
Use replace() with regex
var test = ",,2,4,,,3,,3,,,";
document.write(test.replace(/,+/g,',').replace(/^,|,$/g,''));
replace(/,+/g,',') - To remove multiple comma with one.
replace(/^,|,$/g,'') - To remove comma at starting and ending.

How can I remove a particular element from a string in javascript or check if it's there [duplicate]

This question already has answers here:
Remove characters from a string [duplicate]
(6 answers)
Closed 8 years ago.
I have a quick question
I have string var str="0-12345";
How can I actually remove the dash from the string if there is one in Javascript .. How can I check if a string has a dash , and if it has , remove the dash from it ?
you have forgot to do the homework before you asked here , any way
var str="0-12345";
var is_dashed=(str.indexOf("-") !== -1);
str= str.replace('-',''); //many more ideas , it seems simple to remove all '-'

Categories

Resources