简体   繁体   English

匹配正则表达式,JavaScript中不同的url开始

[英]Match different url start in regex, javascript

A bit confused with regex. 与正则表达式有些混淆。

Url string can be either '/item/new/url/bla/..' or '/#item/url/bla/bla/..' 网址字符串可以是'/item/new/url/bla/..''/#item/url/bla/bla/..'

I need a regex to check start of the string. 我需要一个正则表达式来检查字符串的开始。 In pseudo code it can be described as: 用伪代码可以将其描述为:

(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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM