Skip to content
Advertisement

Regex to match a string that contains substrings separated with dots

I need to get a value from an array using the dot notation. For example:

JavaScript

So what I need to do is check if it’s a valid string by which we could get a value from array.

Constraints:

  • non-whitespace characters only
  • contains at least one dot
  • cannot start or end with a dot
  • every dot must have a non-dot substring before and after it

Cases:

JavaScript

Advertisement

Answer

Try this:

JavaScript

Explanation:

JavaScript

Demo here.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement