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) Jquery右键菜单(来者有分) javascript 简单问题 我看电子货币 javascript 中是否可以读取到php值? 求教: 鼠标单击单元格变色 分不够再加 务求大家帮助! iframe表单的窗口控制问题,请高手来解 跪求IE各版本模拟软件.. 请教xmlHttpReques数据处理问题. 请问javascript能否调用嵌在JSP页面里的java 的变量? 鼠标事件问题(在线等): 关于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)