如何将其拆分为令牌?

时间:2017-02-27 22:56:02

标签: javascript arrays regex

我有这些数据:

//when document is ready    
( document ).ready( function() {

        (function(){ //anonymous function
            // store in this variable the element
        var lTimeoutField = document.getElementById("throttle_sec"),
            //lTimeout = if variable lTimeoutField exist, add what contains, else put 0 , a?b:c is a quaternary operator, google search
            lTimeout      = lTimeoutField ? +lTimeoutField.innerHTML : 0;
         // if timeout is different from 0
        if (lTimeout) {
            // we set an interval, with the name 'lTimer', that will repeat at 1s, or 1000ms, window.setInterval has 2 parameters, a function and the time to repeat the functio basic this function every 1s check if lTimer is >0, and if is update the content in the field, substract-1, and continue until is <0
                var lTimer = window.setInterval (   
//function
            function() {
                   if (lTimeout > 0) {
                           // update the timeout field and substract that variable with -1
                            lTimeoutField.innerHTML = lTimeout;
                            lTimeout--;
                        } else {
                            // we clear the timeout
                            window.clearInterval(lTimer);
                            var lDiv = document.getElementById("throttle_div");
                            if (lDiv) {
                                lDiv.parentNode.removeChild(lDiv);
                                return true;
                            }
                        }
                    },
//time to repeat
                    1000 );
            }})();

我希望将其分成信息标记1 XOR 1 equals 0 1 XOR 0 equals 1 /some test/ -> next data prev<-/now/->/how about this/ asd<-/rege\/x/ /\/\// /\\/ /^\d+$/ <- /\./ /\./ -> /\d/ \w+|/.*?/,但<-->可以在{{1}内进行分类}}
我尝试了this,但在这种情况下->失败了。

&#13;
&#13;
<-
&#13;
&#13;
&#13;

在我的正则表达式中我应该做些什么来涵盖这一部分?

1 个答案:

答案 0 :(得分:1)

假设在启动/子字符串的未转义/之前,您无法获得转义/.../个字符,您可以使用

/\s*(\w+|\/[^\/\\]*(?:\\.[^\/\\]*)*\/)\s*/g

请参阅regex demo

如果可以转义换行符(如CR或LF),则需要将.替换为[\s\S] / [^]以匹配任何字符。

注意:\/[^\/\\]*(?:\\.[^\/\\]*)*\/匹配...

  • \/ - /
  • [^\/\\]* - 除/\
  • 以外的0个字符
  • (?:\\.[^\/\\]*)* - 零个或多个序列
    • \\. - 转义字符
    • [^\/\\]* - 除/\
    • 以外的0个字符
  • \/ - /字符