我有一个字符串:
hello example >> hai man如何使用Java regex或其他技术提取"hai man“?
发布于 2010-11-11 19:10:53
您可以使用正则表达式作为:
String str = "hello example >> hai man";
String result = str.replaceAll(".*>>\\s*(.*)", "$1");发布于 2010-11-11 19:12:05
请参阅run:http://www.ideone.com/cNMik
public class Test {
public static void main(String[] args) {
String test = "hello example >> hai man";
Pattern p = Pattern.compile(".*>>\\s*(.*)");
Matcher m = p.matcher(test);
if (m.matches())
System.out.println(m.group(1));
}
}发布于 2010-11-11 19:05:36
最基本的方法是处理字符串中的字符及其索引。
对于hello example >> hai man使用
String str ="hello example >> hai man";
int startIndex = str.indexOf(">>");
String result = str.subString(startIndex+2,str.length()); //2 because >> two character 我认为它理清了基本的思路。
有很多技巧可以用来解析
另一种更简单的方法是:
String str="hello example >> hai man";
System.out.println(str.split(">>")[1]);https://stackoverflow.com/questions/4153704
复制相似问题