I need a regular expression that matches a String at the beginning of the input which satisfies following conditions:
- start with a letter
- end with a letter or a number
- may contain letters, numbers and spaces
I have this expression so far:
^([a-zA-Z]+[a-zA-Z0-9 ]*[a-zA-Z0-9]+)|[a-zA-Z]
http://userguide.icu-project.org/strings/regexp
The OR statement in the expression is to allow a String that consists of one letter.
The problem is that the second part of the OR statement is always preferred, so when the input is query1, it matches only q.
How can I solve this problem?
Is there a way to simplify the expression? My way seems a little to complex for this relatively simple case.