请大家帮忙看下这个正则如何写
想将字符串 "www.baidu.com/index.html?name=123&title=456 "
替换为 "www.baidu.com/index.html?name= '123 '&title= '456 ' "
尝试着写了一下不起作用,请大家帮忙指点一下,对正则太生疏.
var strurl= "www.baidu.com/index.html?name=123&title=456 ";
strurl.replace(/=(\.*)(&|$)/gi, " '$1 ' ");
alert(strurl)
------解决方案-------------------- <script>
var strurl= "www.baidu.com/index.html?name=1w23&title=4_536 ";
strurl=strurl.replace(/=([\w]*)($|&)/gi, "= '$1 '$2 ");
alert(strurl)
</script>
------解决方案-------------------- <script language= "javascript ">
//alert( ' ')
var a= "www.baidu.com/index.html?name=123&title=456 "
alert(a.replace(/\=(.*?)(\&|$)/g, "= '$1 '$2 "))
//alert(/^\(\d{3}\)\d{3}\-\d{4}$/.test( '(121)123-123 '))
</script>
------解决方案-------------------- <script type= "text/javascript ">
var t = "www.baidu.com\/index.html?name=123&title=456 ";
alert(t.replace(/([^&=]+)(?=&|$)/g, " '$1 ' "));
var t = "www.baidu.com\/index.html?name=&title=456 ";
alert(t.replace(/=([^&]*)(?=&|$)/g, "= '$1 ' "));
</script>
------解决方案-------------------- <script type= "text/javascript ">
/* <![CDATA[*/
var s = "www.baidu.com/index.html?name=123&title=456 ";
alert(s.replace(/(\d+)/g, " '$1 ' "));
/*]]*/
</script>