Javascript清理html代码并仅使用字母数字作为回报

Javascript清理html代码并仅使用字母数字作为回报,javascript,regex,Javascript,Regex,我需要一些帮助,弄清楚我的javascript输出格式 <!doctype html> <html><head> <meta charset="utf-8"> <title>cleaner</title> <script language="javascript" type="text/javascript"> function show (text){ var userInput = docum

我需要一些帮助,弄清楚我的javascript输出格式

 <!doctype html>
 <html><head>
 <meta charset="utf-8">
 <title>cleaner</title>

 <script language="javascript" type="text/javascript">
 function show (text){
 var userInput = document.getElementById('textbox').value;
 userInput = userInput.replace(/\W/g, '');
 userInput = userInput.replace(/ /gi,", ");
 document.getElementById('text').innerHTML = userInput;
 }
 </script>

 </head>
 <body>
 <input type='textbox' name='textbox' id='textbox' value="Title Here"/>
 <input type=button name=button value="OK" onClick="show()"/>
 <div id="text"></div></body></html>
我的结果是

 A_cleanthiskeyword
我想要这样的结果

 a, clean, this, keyword
我应该在替换代码中添加什么? 谢谢

试试这个:

function show (text){
    var userInput = document.getElementById('textbox').value;
    userInput = userInput.match(/[a-z]+/gi).join(", ").toLowerCase();
    document.getElementById('text').innerHTML = userInput;
}

请检查此代码,此代码适用于您

         <!doctype html>
             <html><head>
             <meta charset="utf-8">
             <title>cleaner</title>

             <script language="javascript" type="text/javascript">
            function show ()
{
    var userInput = document.getElementById('textbox').value;
        var num = userInput.indexOf('A');
      userInput    =  userInput.match(/[a-z]+/gi).join(", ").toLowerCase().replace(/ /g, '');
        document.getElementById('text').innerHTML = userInput.substring(num-1);

     }
             }
             </script>

             </head>
             <body>
             <input type='textbox' name='textbox' id='textbox' value="Title Here"/>
             <input type=button name=button value="OK" onClick="show()"/>
             <div id="text"></div>
        </body></html>

清洁工
函数显示()
{
var userInput=document.getElementById('textbox')。值;
var num=userInput.indexOf('A');
userInput=userInput.match(/[a-z]+/gi).join(“,”).toLowerCase().replace(//g');
document.getElementById('text').innerHTML=userInput.substring(num-1);
}
}

下面是代码的JSFIDLE链接

最后一个问题我应该添加什么来删除tehre中的单个字符?这是a,对吗example@Tubestore将
userInput.match(…)
更改为
userInput.match(/[a-z]{n,}/gi)
其中n是最小字符数。由于您使用了userInput=userInput.match(/[a-z]{3,}/gi)。join(“,”).toLowerCase();也行!,如何删除其中的单个字符,@Tubestore检查现在链接和代码都更新了。这是您想要的吗?作为替代,您可以使用
(userInput.match(/[a-z]+/gi)+'').toLowerCase()
,这为您节省了大量工作。sagar原始输出为我提供了一个、clean、this、关键字。我只想删除字母a,所以只有clean,this,关键字是结果。这可能吗?是的,也可以@Tubestore如果收到输出,请标记已应答。
         <!doctype html>
             <html><head>
             <meta charset="utf-8">
             <title>cleaner</title>

             <script language="javascript" type="text/javascript">
            function show ()
{
    var userInput = document.getElementById('textbox').value;
        var num = userInput.indexOf('A');
      userInput    =  userInput.match(/[a-z]+/gi).join(", ").toLowerCase().replace(/ /g, '');
        document.getElementById('text').innerHTML = userInput.substring(num-1);

     }
             }
             </script>

             </head>
             <body>
             <input type='textbox' name='textbox' id='textbox' value="Title Here"/>
             <input type=button name=button value="OK" onClick="show()"/>
             <div id="text"></div>
        </body></html>