我需要跳过一些特殊字符。我已经写了一段代码。但它是纯Java代码。跳过一些特殊字符
String val = menuItemLabelTB.getValue();
boolean spclCharecterCheck = false;
String specialCharacters="!#$%&'()*+,.:;[email protected][]^`{|}~";
for (int i = 0; i < val.length(); i++) {
for (int j = 0; j < specialCharacters.length(); j++) {
if(val.charAt(i) == specialCharacters.charAt(j))
spclCharecterCheck = true;
}
}
如果我想用regex
,以尽量减少复杂性,那么是有可能做到这一点?或者我需要使用其他任何内置的Java函数。
是的,它使用正则表达式是可能的,所以现在是时候让你**学习正则表达式**,所以你就会知道如何构建正则表达式模式。 – Andreas