JS正则替换提取指定字符之间内容等 本帖最后由 wskia 于 2014-04-15 17:14:56 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 alert('北京(今日)【E】/二环(活动)【B】'.replace(/([\s\S]*?)|【[\s\S]*?】/g,''));//北京/二环 alert('345D大B0成-24/美'.replace(/\/.*/g,'').match(/[\u4e00-\u9fa5]/g).join(''));//大成 alert('345D大B0成-24/美'.replace(/\/.*/g,'').match(/\d/g).join(''));//345024 alert('345D大B0成-24/美'.replace(/\/.*/g,'').match(/[a-z]/ig).join(''));//DB alert('345D大B0成-24/美'.replace(/\/.*/g,'').match(/[a-z\d]/ig).join(''));// alert('美/345D大B0成-24'.replace(/.*\//g,'').match(/[\u4e00-\u9fa5]/g).join(''));//大成 alert('美/345D大B0成-24'.replace(/.*\//g,'').match(/\d/g).join(''));//345024 alert('美/345D大B0成-24'.replace(/.*\//g,'').match(/[a-z]/ig).join(''));//DB alert('美/345D大B0成-24'.replace(/.*\//g,'').match(/[a-z\d]/ig).join(''));//345DB024 alert("北京(今日)【E】/二环(活动)【B】".replace(/(.+?)|【.+?】/g,""));alert("345D大B0成-24/美".replace(/\/.*?$/,"").replace(/[\x00-\xff]/g,""));alert("345D大B0成-24/美".replace(/\/.*?$/,"").replace(/\D/g,""));alert("345D大B0成-24/美".replace(/\/.*?$/,"").replace(/[^a-z]/ig,""));alert("345D大B0成-24/美".replace(/\/.*?$/,"").replace(/[^a-z\d]/ig,""));alert("美/345D大B0成-24".replace(/^.*?\//,"").replace(/[\x00-\xff]/g,""));alert("美/345D大B0成-24".replace(/^.*?\//,"").replace(/\D/g,""));alert("美/345D大B0成-24".replace(/^.*?\//,"").replace(/[^a-z]/ig,""));alert("美/345D大B0成-24".replace(/^.*?\//,"").replace(/[^a-z\d]/ig,"")); 1. var str = "北京(今日)【E】/二环(活动)【B】"; str = str.replace(/(\([^\)]*\))|(\【[^\】]*\】)/g,''); console.log(str)2.var str = "345D大B0成-24/美/国"; str = str.substr(0,str.indexOf("/")).match(/[\u4E00-\u9FA5]+/g).join('');//从左向右得到第一个/前的中文 其他的类似改红色正则 console.log(str)3.var str = "美/国/345D大B0成-24"; str = str.substr(str.lastIndexOf("/")).match(/[\u4E00-\u9FA5]+/g).join('');//从右向左得到第一个/后的中文 其他的类似改红色正则 console.log(str) 求救!同样一句JS代码,为什么2个页面,一个能获得焦点,一个获得不了焦点。 iframe控制父窗口的问题 一个火辣辣的问题 执行变量中的脚本 各位帮忙看看, 用JS 下载 EXE 并执行 ,为什么不行?? 大家帮我看看,这个小程序为什么总是报错!有劳各位了! 如何利用JavaScript读取上传文件大小(字节数) web网页如何下载文件?除了用xml.http的方法??? 如何将javascript取得的变量传给asp 两个下拉列表框,如何相应变化??? 关于activex的调用,急救 一个难度比较大的css定位问题position和z-index(急)
alert('345D大B0成-24/美'.replace(/\/.*/g,'').match(/[\u4e00-\u9fa5]/g).join(''));//大成
alert('345D大B0成-24/美'.replace(/\/.*/g,'').match(/\d/g).join(''));//345024
alert('345D大B0成-24/美'.replace(/\/.*/g,'').match(/[a-z]/ig).join(''));//DB
alert('345D大B0成-24/美'.replace(/\/.*/g,'').match(/[a-z\d]/ig).join(''));//
alert('美/345D大B0成-24'.replace(/.*\//g,'').match(/[\u4e00-\u9fa5]/g).join(''));//大成
alert('美/345D大B0成-24'.replace(/.*\//g,'').match(/\d/g).join(''));//345024
alert('美/345D大B0成-24'.replace(/.*\//g,'').match(/[a-z]/ig).join(''));//DB
alert('美/345D大B0成-24'.replace(/.*\//g,'').match(/[a-z\d]/ig).join(''));//345DB024
alert("北京(今日)【E】/二环(活动)【B】".replace(/(.+?)|【.+?】/g,""));
alert("345D大B0成-24/美".replace(/\/.*?$/,"").replace(/[\x00-\xff]/g,""));
alert("345D大B0成-24/美".replace(/\/.*?$/,"").replace(/\D/g,""));
alert("345D大B0成-24/美".replace(/\/.*?$/,"").replace(/[^a-z]/ig,""));
alert("345D大B0成-24/美".replace(/\/.*?$/,"").replace(/[^a-z\d]/ig,""));
alert("美/345D大B0成-24".replace(/^.*?\//,"").replace(/[\x00-\xff]/g,""));
alert("美/345D大B0成-24".replace(/^.*?\//,"").replace(/\D/g,""));
alert("美/345D大B0成-24".replace(/^.*?\//,"").replace(/[^a-z]/ig,""));
alert("美/345D大B0成-24".replace(/^.*?\//,"").replace(/[^a-z\d]/ig,""));
str = str.replace(/(\([^\)]*\))|(\【[^\】]*\】)/g,'');
console.log(str)
2.var str = "345D大B0成-24/美/国";
str = str.substr(0,str.indexOf("/")).match(/[\u4E00-\u9FA5]+/g).join('');//从左向右得到第一个/前的中文 其他的类似改红色正则
console.log(str)
3.var str = "美/国/345D大B0成-24";
str = str.substr(str.lastIndexOf("/")).match(/[\u4E00-\u9FA5]+/g).join('');//从右向左得到第一个/后的中文 其他的类似改红色正则 console.log(str)