如何使用正则表达式?
答案 0 :(得分:2)
我不会给出替换逻辑(过多的勺子喂食),但我可以告诉你如何找到一个单词以z
开头。
public static void main(String args[]){
String s = "abc zdefg hijk asdsaz";
Pattern p = Pattern.compile("\\b(?!z)(\\w+)\\b");
// \\b is word boundary matcher.
// ?! negative lookahead and checks if a word doesn't start with z
// //w+ matches one or more characters only if previuos condition holds true.
Matcher m = p.matcher(s);
while(m.find()){
System.out.println(m.group());
}
}
O / P:
abc
hijk
asdsaz