I have the following code to match:
String(s) in which
.
is not present consecutively, it can be alternatively
let strArr = [
'#foo3.5', // true
'#bar34..34', // false
'.', // true
'#ipv4-1.1.1.1' // true
];
const re = /^([^.]*\.[^.]*)+$/;
strArr.map(
(val, idx) => console.log(`${idx}: ${re.test(val)}`)
);
But, the above code also matches #bar34..34
, which is not desired. I tried changing the *
meta-character in my pattern to +
, but then, it fails to match .
and #ipv4-1.1.1.1
strings.
Also, I want my regex to be small, because it is a part of a very long regex (you can suppose it an Email ID regex). So, what should be the required regex?