该元素包含以下内容,其中所需的解决方案是清除“所有内容”,除了单词和空格之间
var textContent = " +(269) Yukon Makukon"
var cleanContent = textContent.replace(/[^A-Za-z]/g, ``)
document.write(cleanContent);
答案 0 :(得分:5)
在正则表达式中添加空格字符,然后只需.trim()
对其进行格式化即可。
var textContent = " +(269) Yukon Makukon"
var cleanContent = textContent.replace(/[^A-Za-z ]/g, ``).trim();
document.write(cleanContent);
答案 1 :(得分:1)
let textContent = " +(269) Yukon Makukon";
let result = textContent.replace(/[^a-zA-Z ]/g, "").trim();
console.log(result); // => Yukon Makukon
这将删除所有特殊字符以及任何多余的空格。
答案 2 :(得分:1)
或者,您可以使用箭头函数并返回空字符串,或者如果只想忽略它们,则wp_dropdown_pages(array(
'post_type' => 'property',
'property_status' => 'condominium-villas-project',
'selected' => $post->ID,
'name' => 'ID',
'show_option_none' => __('Not selected'),
'echo' => 1,
));
就可以了:
.replace(/[^A-Za-z ]/g, '')
答案 3 :(得分:0)
var textContent = " +(269) Yukon Makukon"
// this way, you can replace them with any character if you wish.
// you were ignoring space ---------------------V
var cleanContent = textContent.replace(/[^A-Za-z ]/g, u=>'');
document.write(cleanContent);