javascript - 匹配某种字符串的正则表达式模式

标签 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>

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

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

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

最佳答案

您可以使用:

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

Working Demo

关于javascript - 匹配某种字符串的正则表达式模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22616534/

相关文章:

javascript - Highcharts堆积条形图: adding categories and data to series

javascript - 异步运行两个 Promise,但优先考虑第一个 Promise 的结果

javascript - 如果数组项包含字符串但不包含其他字符串,则删除字符串

javascript - 需要从javascript中的长字符串中替换字符串

java - 如何用制表符替换行开头的所有空格?

python - 如何使用正则表达式从python字符串中提取不同类型的子字符串?

javascript - Android 代码如何与 WebView 中的 Javascript 代码交互?

javascript - Angular : Add attribute (programmatically) to element with binding

python - 我想从 ":"中提取单词来斜线

regex - gsub - 将所有重复字符减少到一个实例