javascript - 通过正则表达式获取正确的字符串

标签 javascript jquery html

我有以下字符串的假设值:

//start string:
var text1 = 'Me & You';
var text2 = 'Me& You';
var text3 = 'Me &You';
var text4 = 'Me&You';
var text5 = 'Me        &You';
var text6 = 'Me&       You';
var text7 = 'Me     &  You';
//Final string I want to get:
text1: Me You
text2: Me You
text3: Me You
text4: MeYou
text5: Me        You
text6: Me       You
text7: Me       You
//real output:
text1: Me You
text2: Me You
text3: Me &You
text4: MeYou
text5: Me        //Here are many hidden spaces
//and similar outputs
//hypothetical RegExp
var string = 'Me     &  You';
let value = /\S*(&|#|%)\S*/;//for example
let resssC = string.split(value )...

如何获得所需的输出?是正则表达式的问题还是还有其他问题?

最佳答案

正如我认为你必须只替换 &

string.replace(/\&/g,"");

关于javascript - 通过正则表达式获取正确的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45129040/

相关文章:

html - 我的单元格之间有边距

html - CSS - 悬停可见另一个子菜单

javascript - Twitch channel 状态 Chrome

c# - 在没有 @HTML.Beginform 的情况下发布表单并在 asp.net MVC 中使用 Jquery(ajax)

jquery - 切换内联样式背景色

javascript - 模拟 DOM 元素的累积

javascript - 使用 Q 用异步调用填充数组

javascript - AJAX 调用在 IE 11 中不起作用

javascript - 脚本标签 shopify 缺少参数错误

html - 如何仅当右侧有元素时才在 HTML 元素中设置边距