While many of us are familiar with naming conventions in R, regular expressions remain uncharted territory for me and the most dreaded aspect of my programming endeavors. As I dive back into JavaScript, I am grappling with creating precise RegExp to validate correct R object names.
A quick overview: Object names must begin with a period (.) or a lowercase/uppercase letter. If they start with a period, they cannot be followed by a number. After that, alphanumeric characters along with periods and underscores are permitted.
To cut to the chase, here's a snippet of my JavaScript code:
var txt = "._.";
var inc = /^\.(?!\d)|^[a-z\.]/i;
document.write(inc.test(txt));
This method handles the initial part successfully but struggles with something like & [.\w]. I can create a function to address this issue, but is it possible at all to handle this with a single RegExp?