Javascript 要匹配此字符串,请使用正则表达式模式

Javascript 要匹配此字符串,请使用正则表达式模式,javascript,regex,Javascript,Regex,我需要在javascript中使用正则表达式模式匹配以下类型的字符串 E.g. /this/<one or more than one word with hyphen>/<one or more than one word with hyphen>/<one or more than one word with hyphen>/<one or more than one word with hyphen> 只有斜杠(/)和开头的“this”是一

我需要在javascript中使用正则表达式模式匹配以下类型的字符串

E.g. /this/<one or more than one word with hyphen>/<one or more than one word with hyphen>/<one or more than one word with hyphen>/<one or more than one word with hyphen>
只有斜杠(/)和开头的“this”是一致的,并且只包含字母表。

试试这个-

^\/this(?:\/[\w\- ]+)+$

演示

您的问题中存在一些不一致之处,您想要匹配的内容还不太清楚

也就是说,下面的正则表达式将为您想要的字符串提供一个宽松的起点

/this/(?:[\w|-]+/?){1,10}
这假定url中的“”不是故意的。此示例将把url与“/This/”+1到10个额外的“/”块相匹配

(?:)     -> non-matching group
[\w|-]+  -> one or more word characters or a hyphen
/?       -> zero or one slashes
{1,10}   -> 1 to 10 of the previous element, the non-matching group

一开始是“测试”吗?你是说“这个”吗?另外,第二个示例似乎与模式不匹配,因为有一个部分没有带连字符的单词。。。字符串实际上包含连字符而不是空格。我在前面的问题中输入了错误的字符串,然后在regex?@anubhava中使用连字符而不是空格。。谢谢,它使用连字符而不是空格
(?:)     -> non-matching group
[\w|-]+  -> one or more word characters or a hyphen
/?       -> zero or one slashes
{1,10}   -> 1 to 10 of the previous element, the non-matching group