how to remove the following text from a string in javascript? [duplicate] - javascript

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Replace all spaces in a string with '+'
how to remove ,#contacts.Assessor.firstname# #contacts.Assessor.lastname# and
,#contacts.Assessor - Secondary.firstname# #contacts.Assessor - Secondary.lastname# from a
string in javascript?
Thanks

Simply use .replace()
string = string
.replace(',#contacts.Assessor - Secondary.firstname# #contacts.Assessor - Secondary.lastname#', '')
.replace(',#contacts.Assessor.firstname# #contacts.Assessor.lastname#', '');
Also take a loot at this related question

Related

How to replace a string in javascript only when it's comes before another string using regex? [duplicate]

This question already has answers here:
REGEX: Capture Filename from URL without file extension
(5 answers)
JavaScript Regexp to replace a value only when it follows certain characters?
(2 answers)
Closed 3 years ago.
I want to replace xx with . in this string 100x100/<name>xx-somename-xxjpg but only xx comes next to jpg.
'100x100/<name>xx-somename-xxjpg'.replace(/(xx(jpg|jpeg|png))/,'$')
What I get -> 100x100/<name>xx-somename-$
What I expect-> 100x100/<name>xx-somename-.jpg
How do I do it?
'100x100/<name>xx-somename-xxjpg'.replace(/(xx)(?=jpg|jpeg|png)/,'.')

How to format string in JS? [duplicate]

This question already has answers here:
JavaScript .replace only replaces first Match [duplicate]
(7 answers)
Closed 6 years ago.
I would like to have the result :
28,12,2016
From this string "28/12/2016"
I tried :
("28/12/2016").replace('/',',');
==>"28,12/2016"
I don't know how to delete the second /and the " "
use split and join method
var a="28/12/2016";
var ans=a.split("/").join(",");
console.log(ans);

Replacing “index” array string using Javascript regex [duplicate]

This question already has answers here:
Regex using javascript to return just numbers
(14 answers)
Closed 6 years ago.
with the following code can get the 1 in the string.
var match = /[0-9]+/.exec('[1][2]');
console.log(match);
How do i get the 2 and not the 1 ?
Try with this regex
console.log(/(\[[0-9]\])+/.exec('[1][2]'));
I think it's only a matter of escaping the square brackets

How do I get the last character with jquery [duplicate]

This question already has answers here:
How to get the last character of a string?
(15 answers)
Closed 8 years ago.
I have a string I am trying to get the last character with jquery. How would I do that?
var stringTemp = "fieldNameWithIndex_1";
stringTemp.charAt(stringTemp.length-1);
or
stringTemp.slice(-1);
Use .split():
stringTemp.split('_')[1]

how to split into character group? [duplicate]

This question already has answers here:
Split large string in n-size chunks in JavaScript
(23 answers)
Closed 9 years ago.
I want to split string
"abcdefgh"
to
"ab","cd","ef","gh"
using javascript split()
"abcdefgh".split(???)
Can you please help ?
Instead of split, try match:
var text = "abcdefgh";
print(text.match(/../g));
prints:
ab,cd,ef,gh
as you can see on Ideone.

Categories

Resources