Skip to content

Instantly share code, notes, and snippets.

@nommy
Created December 2, 2011 05:28
Show Gist options
  • Save nommy/1421900 to your computer and use it in GitHub Desktop.
Save nommy/1421900 to your computer and use it in GitHub Desktop.
Todays Java Code (regep)
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class regep {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//RT
String str = "RT Screen_Name: testtest";
//1回または0回以上のヒット //" ([a-z-A-Z]+):"
String regex = "(RT ([a-zA-Z_0-9]+):)";
//行頭でのヒット
//String regex = "^RT ";
Pattern pt = Pattern.compile(regex);
Matcher mt = pt.matcher(str);
if(mt.find()){
String result = mt.group();
//String resultset1 = mt.group().substring(0,3);
int strLength=result.length();
str = str.substring(strLength+1, str.length());
String resultset2 = mt.group().substring(3,strLength-1);
//Print-Debug
System.out.println(resultset2);
System.out.println(str);
//System.out.println("match");
}else{
//Print-Debug
System.out.println("unmatch");
}
//HashTag
str = "testtest #Keyword";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment