package xmlchars;
import java.util.regex.Pattern;
public class TestRegex {
public static final String SPECIAL_CHARACTERS = "(?i)^[^a-z_]|[^a-z0-9-_.]";
public static void main(String[] args) {
// TODO Auto-generated method stub
String name = "#1998St #";
Pattern pattern = Pattern.compile(SPECIAL_CHARACTERS);
System.out.println(pattern.matcher(name).replaceAll(""));//gives wrong output 1998St
}
}
基本上我想要实现的是
- 仅以 az 和 _ 开头的字符串
- 包含 az 0-9 _ - 的字符串。开始后
- 整个字符串不区分大小写