无敌简单的正则,我换了很多方法都不正确,郁闷
1,找出匹配 单词create 加任意空格或换行或回车 加单词procedure 后面可以有任意字符串
我写的是 .matches("create(\n|\r|\b)*"procedure[.\n]")
2,找出specific这个单词后的 一个单词,我考虑用空格来取出这个单词
谁能帮帮我???
谢谢啦
无敌简单的正则,我换了很多方法都不正确,郁闷
1,找出匹配 单词create 加任意空格或换行或回车 加单词procedure 后面可以有任意字符串
我写的是 .matches("create(\n|\r|\b)*"procedure[.\n]")
2,找出specific这个单词后的 一个单词,我考虑用空格来取出这个单词
谁能帮帮我???
谢谢啦
[code="java"]
package net.sulin.regular;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegularWord {
public static void main(String[] args) {
String test = "fsf$ specific $ test@#$dfsdff@3";
String first = null;
String end = null;
Pattern p = null;
Matcher m = null;
//第一次提取
p = Pattern.compile("specific[^a-zA-Z]+([a-zA-Z]+)");
m = p.matcher(test);
while (m.find()){
String temp = m.group();
first = temp.substring("specific".length(), temp.length());
}
//第二次提取
p = Pattern.compile("[^a-zA-Z]+");
m = p.matcher(first);
while (m.find()){
String temp = m.group();
System.out.println(temp.length());
end = first.substring(temp.length(), first.length());
}
System.out.println(end);
}
}
[/code]
:P :P 上午看NCAA、 闲着没事干, 就帮你贴一个完整的程序吧