Javascript regex multiple captures again

后端 未结 2 1425
天涯浪人
天涯浪人 2020-12-20 17:07

Ok, I think I need to repost my question that was originally:

Javascript Regex group multiple

with a full example. I have:

        var text         


        
2条回答
  •  囚心锁ツ
    2020-12-20 17:48

    This is what works:

               var text = ""+
                "                           " +
                "                           " +
                "                          " +
                "                           " +
                "       " +
                "        " +
                "                          " +
                "";
    
            var regex = /<([a-zA-Z]*?):([a-zA-Z]*?)\s([\s\S]*?)>/g;
            var match = null;
            while ( (match = regex.exec( text )) != null  )
                console.log(match)
    

    Notice the /g which seems to be neccessary

提交回复
热议问题