I am trying to write a regex for a valid java identifier name: I have tried this:
([a-zA-Z_$][a-zA-Z\d_$]*)
but it is accepting spaces also. However, I didn't allowed space to be considered as a match.
Any idea?
I am trying to write a regex for a valid java identifier name: I have tried this:
([a-zA-Z_$][a-zA-Z\d_$]*)
but it is accepting spaces also. However, I didn't allowed space to be considered as a match.
Any idea?
You need to include the start
and end
markers to enforce that the entire string matches the regex. Otherwise, it passes if any part of the string matches.
^([a-zA-Z_$][a-zA-Z\d_$]*)$