Побег как обычно:
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
///
Это скомпилируется с этим регулярным выражением:
/\#(?:.*\/)?(\w+\.html)$/
И \#
совпадает с #
в регулярном выражении JavaScript.
Вы также можете использовать escape Unicode \u0023
:
matches = window.location.hash.match ///
\u0023 # 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
///
Но не многие люди признают \u0023
хеш-символом, поэтому \#
, вероятно, лучший выбор.