日期:2014-05-16  浏览次数:20404 次

关于字符串截取
一个字符串

s   =   "xxxx_event ";
xxxx不固定长度

我现在想到得到XXXX到底是什么?

------解决方案--------------------
<script language=javascript>
s = "xxxx_event ";
s2 = "xxxx222211_event ";
s3 = "xxxx222211event_event ";
//xxxx不固定长度
var re=/(.*?)_event$/
alert(s.replace(re, "$1 "))
alert(s2.replace(re, "$1 "))
alert(s3.replace(re, "$1 "))

</script>
------解决方案--------------------
<script type= "text/javascript ">
var s = "xxxx_event ";
var ary=s.split( "_ ");
alert(ary[0]);
</script>
------解决方案--------------------
var s= "a_event_event ";
var str2=s.substr(0,s.length-6)
document.write(str2)