简体   繁体   English

帮助使用JavaScript正则表达式

[英]Help with javascript regular expression

I am unable to do a validation for string sometext.sometext.sometext.sometext.sometext.... 我无法验证字符串sometext.sometext.sometext.sometext.sometext ....

I have tried with this regular expression ^[\\w]*.{1,}[\\w]$ matches the above string but if i give more than one dots consecutively inbetween the text for eg. 我已经尝试过使用此正则表达式^ [\\ w] *。{1,} [\\ w] $匹配上面的字符串,但是如果我在例如之间连续输入多个点。 sometext.sometext.....sometext above regular expression matches this also. 正则表达式上方的sometext.sometext ..... sometext也与此匹配。

Any help is appreciated. 任何帮助表示赞赏。

Thanks in advance. 提前致谢。

{1,} means that there is at least one occurence. {1,}表示至少发生一次。 If you want exactly one occurence, just use the character as is. 如果您只想出现一种情况,请按原样使用该字符。 Also, you need to escape the dot in your regex, since it stands for "any character" if you don't. 另外,您需要对正则表达式中的点进行转义,因为如果不是,则代表“任何字符”。

The following should work if you want to allow 1-n non-empty string parts separated by dots: 如果要允许以点分隔1-n个非空字符串部分,则下面的方法应该起作用:

^\w+(\.\w+)*$

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

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