本帖最后由 wskia 于 2014-04-15 17:14:56 编辑

解决方案 »

  1.   

    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
      

  2.   


    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,""));
      

  3.   

    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)