I need to match the following pattern: NNN
324324.234324.234324 matches, as well as 1.1.1
(\d*\.\d*\.\d*)
Problem is, it matches NN already at the second dot, so, how can I make the following number mandatory ?
Use ^
and $
anchors and also change *
to +
since at least one number is required
also, (\\d*\\.){2}
can be used to simplify \\d+\\.\\d+\\.
[ '324324.234324.234324', '324324.234324.' ].forEach(test => console.log(/^(\\d+\\.){2}\\d+$/.test(test)) );
更改为一个或多个非贪婪+?
(\\d+?\\.\\d+?\\.\\d+)
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.