When I needed to match a simple open-value JavaScript variable, I used the following RegEx:
\s*[a-zA-Z0-9$_]+\s*
Now I need to add support for nested properties, i.e. there can be dots (.) in the name, with the following considerations:
.cannot be in the beginning or end- a single
.on its own is not valid - repeated dots (
a..b) are not allowed
What would be the right/simplest way to amend such a RegEx pattern?
If it makes any difference, I'm only interested in a version that will work under Node.js
Valid Examples
aa.ba.b.c_.$.123
Invalid Examples
- ``
..aa.a..b
^[a-zA-Z_$][\w$]*(?:\.[\w$]+)*$, too.