I’m trying to use a regex to match a pattern such as (letter(letter|number))*, I mean a string with infinite length but with a “start with a letter, then be either a letter or a number” rule.
So I’m using this pattern #"\w+[\w|\d]*" in clojure, but if I use just a number it validates, just like the code below, what am I doing wrong?
(re-matches #"\w+[\w|\d]*" "1")
The other answers look good for the question you asked, but it sounds like you really might be looking to validate identifiers. Note that the Java API provides some useful utility methods to do just that. Sometimes being explicit is better than a regex.
e.g.
In java 6 and later you can do this: