求个正则表达式,谢谢
本帖最后由 dunerunner 于 2013-12-01 10:01:43 编辑
bbs.csdn.net/topics/1111111 返回 /topics/1111111
/etc/ssh/sshd_config 返回 /ssh/sshd_config
应该怎么写这个正则表达式 就是去掉第一个'/'左边的字符串
------解决方案--------------------p = /\/?[^\/]+(\/.+)/;
s = 'bbs.csdn.net/topics/1111111';
document.write(s.replace(p, '$1')+'<br>');
s = '/etc/ssh/sshd_config';
document.write(s.replace(p, '$1')+'<br>');
/topics/1111111
/ssh/sshd_config
------解决方案--------------------<script type="text/javascript">
var a=['bbs.csdn.net/topics/1111111','/etc/ssh/sshd_config'];
var reg=/^\/?[^/]*/;
for(var i=0;i<a.length;i++){
a[i]=a[i].replace(reg,'');
alert(a[i]);
}
</script>
------解决方案--------------------var str = "/etc/ssh/sshd_config";
str = str.replace(/^\/?[^\/]+/,"");