Entries Tagged ‘regex’:

字符引用和空白字符

看到最近有讨论,前些日子刚好也收集过一些资料,补充如下:

字符引用

在 html 中,有三种字符引用方式(参考 HTML5 规范):

  1. Named character references, 通过名称来引用。在 HTML 4.01 中称之为 Character entity references(字符实体引用)比如 < >   ", 这里有一份详细列表 named-character-references
  2. Decimal numeric character reference, 通过十进制数值来引用。比如 å И
  3. Hexadecimal numeric character reference, 通过十六进制数值来引用。比如 å 水

在 HTML 4.01 中,上面 2 和 3 归为一种:Numeric character references(字符数值引用)。
这里有份非常好的对照表:XHTML Character Entity Reference
阅读全文 »

Tags: , , ,

Image Grabber Booklet

代码:

var o = "<ol>", bd = document.body;
bd.innerHTML.replace(
        /(<img[^>]*)(src *= *("[^"]*"|'[^']*'|[^ >]*))/ig,
        function(m, t, c, src) {
            t = src; c = src.charAt(0);
            if (c == '"' || c == "'") t = t.slice(1, -1);
            o += "<li>" + t + " <img src=" + src + " /></li>";
        });
bd.innerHTML = o + "</ol>";

Booklet 添加页面:img-src-regexp-test.html(WordPress 的过滤好讨厌,只好放在独立页面里)

针对该功能,更简单明了的思路是用 getElementsByTagName(“img”) 来实现,但性能不如正则。

Tags: , , ,