java - how to put - in [] in regular expression -
i want use [] indicate group of acceptable characters, among -. directly putting - in [] impossible. example, want put a-za-z , - inside [], cannot directly write [a-za-z-]. how should write -? using \ quote? or else?
i using in java.
edit: see below answer. if using - in [] , feel wrong, please pay attention - might link 2 characters, , convention put - last character.
you can write [a-za-z-]. in fact, that's how supposed it: make - last character.
(as discussed in comments, not required make - last character. convention, however, should last character, in order make regex easier read.)
Comments
Post a Comment