-3

我正在尝试在 Java 中制作 RegEx 并测试一个单词以查看它是否包含一些字符,例如a-zorA-Z或or or or or 0-9or "$"or "_"without the rest of the possible characters including the space。

我试过:

boolean test = Pattern.matches("[a-zA-Z||[_]||[$]]",wordTest);

或者

boolean test = Pattern.matches("[a-z]|[A-Z]|\\*|_+",wordTest);

所以有些词像 : "&_bird""bi_r&" 但不是" bird""b ird^("例如。

我在网上寻找解决方案已经几个小时了,但我什么也没找到。

4

1 回答 1

1

boolean test = Pattern.matches("[a-zA-Z0-9_$]+", wordTest);

于 2013-01-02T22:24:12.823 回答