[英]Removing file extension and special characters
Hi what i am trying to remove file extension and special chracters but my problem is slight difficult thats my existing code 嗨,我正在尝试删除文件扩展名和特殊字符,但是我的问题有点困难,那就是我现有的代码
<script>
var pathname = window.location.pathname;
pathname = pathname.replace(/[^a-zA-Z0-9]/g,' ');
window.location="http://mimuz.com/search.php?keywords="+pathname;
</script>
In path name there are three portions forexample 在路径名中,例如有三个部分
/videos-of-stars-and-stellites-etc_fe5eb9bf1.html
to best explain url 最好地解释网址
videos-of-stars-and-stellites-etc = Video name 明星和明星的视频等=视频名称
than comes underscore _ 比下划线_
and than 然后
fe5eb9bf1= This is unique video ID fe5eb9bf1 =这是唯一的视频ID
than lastly 比最后
.html = this is extension .html =这是扩展名
What i want to do is I want to remove any slashes, hyphens, dots and replace them with spaces and lastly i want to completely remove _fe5eb9bf1.html this type of porting from my urls any idea ? 我想做的是我想删除任何斜杠,连字符,点并将它们替换为空格,最后我想从我的url中完全删除_fe5eb9bf1.html这种类型的移植有什么主意吗?
SO at the end i will get the result like this 所以最后我会得到这样的结果
videos of stars and stellites etc
pathname.replace(/_[^.]+.[a-z]+$/, '').replace(/[^a-zA-Z0-9]/g,' ');
这是小提琴: http : //jsfiddle.net/bPVbk/
Easiest approach is just to use the split method. 最简单的方法就是使用split方法。 Something like
就像是
var pathname = window.location.pathname;
var videoname = pathname.split("_")[0];
videoname = videoname.replace(/[^a-zA-Z0-9]/g,' ');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.