0
即时尝试使用REGEX拆分字符串。问题是,分裂时,增加了一个空的空间,我的字符串数组在java中分割为字符串数组添加空格
public static String[] line;
line=this.classMetodos.split(meth.regexMethHead);
meth.regexMethHead作为正规表示我想和分裂。
给出的输出是下一个:
Metodos Contenido [0]:
Metodos Contenido [1]:{洛尔;}
Metodos Contenido [2]:{洛尔;} }
输出希望是:
Metodos Contenido [0]:{洛尔;}
Metodos Contenido [1]:{笑;}}
正则表达式中使用
正则表达式中使用:
public static String regexAccess = "(public|private|\\s*)";
public static String regexStatic = "(static|\\s*)";
public static String regexReturnType = "(String|double|void)";
public static String regexMethName = "([a-z]|[A-Z])([a-z]|[A-Z]|[0-9])*";
public static String regexVariableName = "([a-z]|[A-Z])([a-z]|[A-Z]|[0-9])*";
public static String regexString = "\"([a-z]|[A-Z]|[0-9])*\"";
public static String regexArgs="(\\(\\)|\\(("+regexReturnType+"\\s*"+regexVariableName+")\\))";
public static String regexMethContent="\\{(.*|\\n*|\\t*)*\\}";
//complete regular expression
public static String regexMethHead = regexAccess +
"\\s*"+
regexStatic+
"\\s*"+
regexReturnType+
"\\s*"+
regexMethName+
"\\s*"+
regexArgs;
输入字符串
public static String meth= "public static void jenny(String lolito){\n\t lol;\n\n\t}";
public static String meth2= " public void Lolamer(String jeny){\n\t lol;\n\n\t}";
public static String variables ="static String e =\"lol\";";
public static String pseudoClass="public class torito{"+"\n"+variables+"\n"+
meth+"\n"+meth2+"}";
public static String regexClassName = "([a-z]|[A-Z])([a-z]|[A-Z]|[0-9])*";
public static String regexClassContent="\\{(.*|\\n*|\\t*)*\\}";
public static String regexCLass="^(public|private|\\s*)\\s*class\\s+"+
regexClassName+""+
regexClassContent+"";
记住我的正则表达式和字符串来自其他职业和IM拉他们在另一个类别的分裂
谢谢
提供使用的输入字符串和正则表达式。 – anubhava 2014-12-04 21:00:23
刚刚编辑与输入字符串和正则表达式使用的帖子!帮帮我!! – Hbassuki 2014-12-04 21:06:08
让我把你介绍给我的朋友,[ANTLR](http://www.antlr.org/)。 – 2014-12-04 21:27:53