我尝试匹配jQuery Mobile URL的散列片段,如下所示:
matches = window.location.hash.match ///
# # we're interested in the hash fragment
(?:.*/)? # the path; the full page path might be /dir/dir/map.html, /map.html or map.html
# note the path is not captured
(\w+\.html)$ # the name at the end of the string
///但是,问题是在编译后的JS文件中,#符号从regex中被砍掉了,因为它被视为注释的开始。我知道我可以切换到普通的正则表达式,但是有没有办法在heregex中使用#?
发布于 2012-02-29 14:34:32
实现者在这里。Heregex注释使用一个简单的正则表达式(/\s+(?:#.*)?/g)用空格完全删除,因此#之前的任何非空格字符(或将其放在最前面)都可以工作。
$ coffee -bcs
/// [#] ///
/// (?:#) ///
///#///
// Generated by CoffeeScript 1.2.1-pre
/[#]/;
/(?:#)/;
/#/;https://stackoverflow.com/questions/9492954
复制相似问题