Reputation: 501
I am trying to replace / remove multiple Charactes out of a String. From Sharepoint i take multiple Values as far as i can see i cannot remove those ID Informations while i am get the Values out of a list with sharepointPlus Script. So i try to do it later with jquery and replace. What i get from the List is the following:
Structure to be removed: ;#number and ;# after the Device Name.
As i can see the structure is different, the Main Entries has ID;#Name;# the Last One just ID;#Name
The part of the script that i currently use is:
$("td.affectedDevices:contains(';#')").each(function() {
$(this).html(function(index, text) {
return text.replace('0', '')
.replace('1', '')
.replace('2', '')
.replace('3', '')
.replace('4', '')
.replace('5', '')
.replace('6', '')
.replace('7', '')
.replace('8', '')
.replace('9', '')
.replace(';#', '');
});
});
I am using this Code on another Place where i take just one Entry out of the Table, then it works.
The Problem is, the JS Above takes the First "Number;#" entry of each String... AND the Number of the Device as you can see in the screenshot below:
Should be Galaxy S6 <br />
Galaxy S6 edge and so on...
i am found already some similar questions & answers here but the solutions don't worked at all...
Replacing Wildcard Text the solution looks good but
$("td.affectedDevices:contains(';#')").each(function() {
$(this).html(function(index, text) {
return text.replace(/\([0-9]\);#/, '');
});
});
Doesn't have any effect... Anyone can help me to solve this? Or a better idea to do the whole thing?
Thanks for your help Kind regards
Upvotes: 0
Views: 3202
Reputation: 2683
$("td").each(function() {
$(this).html(function(index, text) {
return text.replace(/[0-9]?;#/g, '').replace(/^[0-9]/g, '');
});
});
Hope this would help you.
Here is the working fiddle : https://jsfiddle.net/1u6brd3m/
Upvotes: 1
Reputation: 1486
Change your code to this:
$("td.affectedDevices:contains(';#')").each(function() {
var string = $(this).html(),
split = string.split('#'),
newContent = '',
re = /^[a-zA-Z]+$/;
$.each(split, function( key, value ) {
if(/^[a-zA-Z]/.test(value)) newContent = newContent + value.replace(';', '') + '<br />';
});
$(this).html(newContent);
});
Working example: https://jsfiddle.net/vgkyoywq/
Good luck!
Upvotes: 1