How to use # as part of CoffeeScript heregex?

后端 未结 2 618
萌比男神i
萌比男神i 2021-01-19 10:42

I\'m trying to match the hash fragment of a jQuery Mobile URL like this:

    matches = window.location.hash.match ///
        #                   # we\'re in         


        
2条回答
  •  抹茶落季
    2021-01-19 11:03

    Implementer here. Heregex comments are removed altogether with whitespace using a simple regex (/\s+(?:#.*)?/g), so any non-whitespace character before # (or placing it at the very beginning) works.

    $ coffee -bcs
      /// [#] ///                      
      /// (?:#) ///
      ///#///       
    
    // Generated by CoffeeScript 1.2.1-pre
    /[#]/;
    
    /(?:#)/;
    
    /#/;
    

提交回复
热议问题