aaaa.bbbb.cccc1111.2222.3333各位好,现在需要一个匹配如上格式的正则表达式(连续四位相同),该怎么写?
谢了。

解决方案 »

  1.   

    alert(/^(.)\1{3}\.(.)\2{3}\.(.)\3{3}$/.test('1111.2222.3333'));//true
    alert(/^(.)\1{3}\.(.)\2{3}\.(.)\3{3}$/.test('aaaa.bbbb.cccc'));//true
    alert(/^(.)\1{3}\.(.)\2{3}\.(.)\3{3}$/.test('aaaa.bbbb.ccccc'));//false
    alert(/^(.)\1{3}\.(.)\2{3}\.(.)\3{3}$/.test('aaaa.bbbb.ccck'));//false
      

  2.   


    var str = 'aaaa.bbbb.3333';
    var re = /^(\w)\1{3}(\.(\w)\3{3})*$/i;   //A~Z,a~z,0~9,_
    alert(re.test(str))楼主 试试
      

  3.   

    <html xmlns:v="urn:schemas-microsoft-com:vml">
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
            <title>Test</title>
        </head>
        <body>
            <input id="inputbox" type="text" value="" />
            <script>
             var reg = /^([a-zA-Z\d])\1{3}(?:\.([a-zA-Z\d])\2{3})*$/g;
             document.getElementById('inputbox').onchange = function(){
             alert(reg.test(this.value));
             }
            </script>
        </body>
    </html>