简体   繁体   中英

looking for correct regular expression for pattern match in javascript

I tried searching stackoverflow for various combination but some or other thing stops working.

I am new to REGEX.

My input is <abc.1.1.1 or abc.1.1 or abc.1 --> case insensitive digits can be between 1-9 positive

var pattern= /[a-zA-Z].[1-9].[1-9].[1-9]$/;

the above pattern still accepts abc.a1.b.1

I am trying for following patterns
abc.1.1.1
or
abc.1.1
or
abc.1

Any help would be appreciated

You should use literal . as just . means "any character" Also you could improve it a bit using global and ignoreCase flags. Also use anchors ^ and $

var pattern= /^[a-z]+\.(([1-9]\.))+[1-9]$/ig;

DEMO

这种模式会起作用

var pattern = /[a-z]*\.([0-9]\.?){,3}/i;

你的

try this code
[a-z]+\.((([1-9]\.))*[1-9]+)*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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