zoukankan      html  css  js  c++  java
  • (五)JS学习笔记

    Sizzle词法解析

    sizzle对于分组过滤处理都用正则,其中都有一个特点,就是都是元字符^开头,限制匹配的初始,所以tokenize也是从左边开始一层一层的剥离。

    •可能会应用到正则如下:

    // 空白
    var whitespace = "[\x20\t\r\n\f]";
    
    // 匹配后任意字符,字母或数字或-,ascii值非x00-xa0范围内的字符
    var characterEncoding = "(?:\\.|[\w-]|[^\x00-\xa0])+" 
    
    var identifier = characterEncoding.replace( "w" , "w#" )  
    
    // 匹配关系符> + ~
    var rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" )  
    
    // 匹配=[非'非"]
    var rattributeQuotes = new RegExp( "=" + whitespace + "*([^\]'"]*?)" + whitespace + "*\]" , "g" )  

    •正则组合:

    ///^#((?:\.|[w-] | [^x00-xa0] ) +)/var ID = new RegExp("^#(" + characterEncoding + ")")

    匹配ID,例如:$('#id')

    var TAG =  new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" );

    匹配标签,例如:$('input')

    var Class = new RegExp( "^\.(" + characterEncoding + ")" );

    匹配class名,例如:$('.test')

    attributes = "\[" + whitespace + "*(" + characterEncoding + ")" + whitespace +
                   "*(?:([*^$|!~]?=)" + whitespace + "*(?:(['"])((?:\\.|[^\\])*?)\3|(" + identifier + ")|)|)" + whitespace + "*\]"
    匹配属性选择器,例如:[arr^='val']
       捕获组1:characterEncoding :匹配例子中arr
       捕获组2:([*^$|!~]?=):匹配例子中^=
       捕获组3:['"]:匹配例子中'
       捕获组4:(?:\\.|[^\\])*? 解释一下这个外层捕获和后面的任意数量字符或非字符,内层有?:是不捕获的,匹配例子中的val
       捕获组5:匹配identifier,匹配[id=#a]的情况
     
    pseudos = ":(" + characterEncoding + ")(?:\(((['"])((?:\\.|[^\\])*?)\3|((?:\\.|[^\\()[\]]|" + attributes.replace( 3, 8 ) + ")*)|.*)\)|)"  
    匹配伪类表达式,例如li:nth-child(2n+1)
       捕获组1:characterEncoding :匹配例子中nth-child
       捕获组2:匹配例子中的2n+1
       捕获组3:匹配' or "
       捕获组4:匹配和后面任何字符或非字符
       捕获组5:匹配不再' or "内的和后面任意字符或非()[]字符或attributes
  • 相关阅读:
    Socket编程注意接收缓冲区大小
    Ubuntu 14.04环境变量修改
    python模块------json
    解决ssh连接linux系统特别慢的问题
    centos7 安装 ftp 服务及创建 repo源
    qcow2镜像制作
    k8s-helm01-----helm基本使用
    mysql常用sql
    js中自执行函数(function(){})()和(function(){}())区别
    npm镜像指定用淘宝镜像去下载
  • 原文地址:https://www.cnblogs.com/huair_12/p/4181973.html
Copyright © 2011-2022 走看看