可以通过以下步骤实现:
match()
方法结合正则表达式来匹配字符串中的破折号单词。例如,可以使用/[\w-]+/g
的正则表达式来匹配包含破折号的单词。each()
方法遍历匹配到的单词列表,并使用replace()
方法去除破折号。以下是一个示例代码:
// 获取包含破折号的字符串
var str = "This is a test-string with hyphenated-words.";
// 使用正则表达式匹配破折号的单词
var words = str.match(/[\w-]+/g);
// 遍历匹配到的单词列表,去除破折号
$.each(words, function(index, word) {
words[index] = word.replace(/-/g, '');
});
// 输出不含破折号的单词
console.log(words);
以上代码会输出一个不含破折号的单词列表:["This", "is", "a", "test", "string", "with", "hyphenated", "words"]
。
对于这个问题,腾讯云没有特定的产品与之相关。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云