javascript - Replace a string word with empty space with js -
i have following string:
var string = "deluxe 3 bed private"
and following code replace "private" word empty space:
var rooms = ["basic", "standard", "superior", "deluxe", "private"]; //var room = "room"; vwo_$(document).ready(function(){ wri.eventbus.on('ui:microsite:availabilitystore:refresh', function(){ var roomname = $(".roomnamelink"); roomname.each(function(){ (var = 0; < rooms.length; i++) { var pattern = "[^\s]" + rooms[i]; var regex = new regexp(pattern); string = string .replace(regex, " "); } }); })
but regex wrong.
if word "private" found in string want replaced empty space.
var string = "deluxe 3 bed"
i want replace of words found in rooms array empty space can use 1 regex possible words
var regex = /\b(basic|standard|superior|deluxe|private)\b/gi
and use string#replace
method
var string = "deluxe 3 bed private" string.replace(regex, '')
Comments
Post a Comment