I am currently developing a program which filters words based off of a txt file that has words inserted into it separated by commas.
The problem I am having is when I try putting regular expressions inside my txt file jQuery treats it as a string ignoring the regular expression entirely.
How can I make it so that I can put words inside my txt file in a reg expression format so that I only have the write a filtered word only once depending on how many different formats a viewer may type it.
If this is not possible can someone point me in the right direction to achieve this function. Any help would be appreciated. Thank you.
Javascript:
// This grabs the data from the txt file and splits each word my commas
$.get('word-list.txt', function(data) {
pbfFilterWords = data.split(', ');
pbfFilterWords.forEach(function(word){
pbfWordList = word;
});
// This defines a global variable so the filter button has a list of words to filter with
var pbfWordList = pbfFilterWords;
//console.log(pbfWordList);
// Function for filter button
$('.pbf-link-container[contenteditable]').html;
$('#pbf-filter').click(function(){
var $pbfOutput = $('.pbf-link-container[contenteditable]').html();
// Array of words for filter
var pbfFilterWords = pbfWordList;
// Output to new DIV and remove specified keywords from pbfFilterWords
$('.pbf-link-output').html($pbfOutput);
// To make pbfFilterWords not case sensitive
$.expr[":"].contains = $.expr.createPseudo(function(arg) {
return function( elem ) {
return $(elem).html().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});
// Function to output the filtered words
$.each(pbfFilterWords , function(i , val){
$('.pbf-link-output > div:contains("'+val+'")').remove();
});
});
});
word-list.txt:
'(Jennifer|Jen|Jenny)\b\w+\b' , baby bullet, baby-bullet, 'back2life', 'back-2-life'