打开http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js
看了一眼,jquery用的正则出乎意料的少呀。
// A simple way to check for HTML strings or ID strings // (both of which we optimize for) quickExpr = /^[^<]*(<[\w\W]+>)[^>]*$|^#([\w-]+)$/, // Is it a simple selector isSimple = /^.[^:#\[\.,]*$/, // Check if a string has a non-whitespace character in it rnotwhite = /\S/, // Used for trimming whitespace rtrim = /^(\s|\u00A0)+|(\s|\u00A0)+$/g, // Match a standalone tag rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
后面还用到了一些比较简短的正则

本文探讨了jQuery源码中使用的正则表达式,包括用于快速检查HTML字符串、简单选择器匹配及字符串非空白字符检查等。通过对这些简洁正则表达式的分析,有助于理解jQuery如何高效处理DOM操作。
844

被折叠的 条评论
为什么被折叠?



