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}`);
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(">"));
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>"
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.
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 '-'