java - Regex pattern for special condition -
input field hold alphabets, space, numbers, defined following regex
[a-za-z ]{1,150}
need include parenthesis , hyphen in above regex.
kindly advise.
the tricky item hyphen: must not come between characters, because has special interpretation. put in first or in last position, this:
[a-za-z0-9 ()-]{1,150}
i added 0-9
because said want allow digits well.
hyphen can anywhere in input
note position of hyphen in regex character class (the construct enclosed in square brackets) has nothing position of hyphen in text being matched. order of characters inside character class not significant, except 2 cases when character has special interpretation: hyphen -
between 2 characters defines range, , ^
@ beginning defines negation.
Comments
Post a Comment