如何在javascript中制作正则表达式来重复(how to make an regular expression in javascript to repeat)

编程入门 行业动态 更新时间:2024-10-28 19:28:13
如何在javascript中制作正则表达式来重复(how to make an regular expression in javascript to repeat)

如何使其验证此字符串:

word:word,word:word,

我写的这篇文章仅适用于:

word:word,enithinggg

这是错的。

/^(^([0-9a-zA-Z!\? ])+\:([0-9a-zA-Z!\?. ])+\,)+$/i

How can I make it to validate this string:

word:word,word:word,

What I wrote this and works only for:

word:word,enithinggg

which is wrong.

/^(^([0-9a-zA-Z!\? ])+\:([0-9a-zA-Z!\?. ])+\,)+$/i

最满意答案

/^(([0-9a-zA-Z!\?])+\:([0-9a-zA-Z!\?])+\,?)+$/

应该这样做。 你在第一组中有^ ,强迫它匹配换行符。 我对javascript正则表达式不太熟悉,所以我不确定最后i在做什么。

您可以在http://rubular.com上运行快速测试

/^(([0-9a-zA-Z!\?])+\:([0-9a-zA-Z!\?])+\,?)+$/

should do it. You had ^ inside the first group, forcing it to match a newline. I'm not too familiar with javascript regular expressions, so I'm not sure what the i at the end was doing.

You can run quick tests on http://rubular.com

更多推荐

本文发布于:2023-07-29 18:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1318700.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   正则表达式   javascript   repeat   regular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!