与正则表达式有点混淆。
网址字符串可以是 '/item/new/url/bla/..'
或 '/#item/url/bla/bla/..'
我需要一个正则表达式来检查字符串的开头。用伪代码可以描述为:
(both "/#item/" or "/item/" at the start of a string should be true).test(url)
最佳答案
/^\/#?item\//.test('/#item/new/url/bla/'); // true
/^\/#?item\//.test('/item/new/url/bla/'); // true
关于javascript - 匹配正则表达式、javascript 中的不同 url 开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17742249/