In: Computer Science
Write the RE for identifiers that can consist of any
sequence of letters (l) or digit (d) or "_"
but the first char must be a letter and the last char
cannot be a "_" (10)
RE is
/^(([A-Za-z])|([A-Za-z][A-Za-z0-9_]*[A-Za-z0-9]))$/
What each word signify:
^ : start of string
[ : beginning of character group
a-z : any lowercase letter
A-Z : any uppercase letter
0-9 : any digit
_ : underscore
] : end of character group
* : zero or more of the given characters
| : or operation
( : used for grouping regex
):used for grouping regex
$ : end of string
It can be divided into two parts:
The first part is their to help regex use for a single letter input every other case will handled by the second part