正则表达式模式匹配一​​种字符串 [英] regex pattern to match a type of strings

查看:63
本文介绍了正则表达式模式匹配一​​种字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to match the below type of strings using a regex pattern in 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>

所以这个单一模式应该匹配这两个字符串:

So this single pattern should match both these strings:

1. /this/is/single-word
2. /this/is-more-than/single/word-patterns/to-match

开头只有斜杠(/)和'this'字符串是一致的,只包含字母。

Only the slash (/) and the 'this' string in the beginning are consistent and contains only alphabets.

推荐答案

您可以使用:

\/this\/[a-zA-Z ]+\/[a-zA-Z ]+\/[a-zA-Z ]+

这篇关于正则表达式模式匹配一​​种字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆