[英]split in java adds empty space to string array
im trying to split a string using a REGEX. 我试图使用正则表达式拆分字符串。 The problem is that when splitting it adds an empty space to my String Array
问题是,拆分时会在我的字符串数组中添加一个空格
public static String[] line;
line=this.classMetodos.split(meth.regexMethHead);
meth.regexMethHead being the regular expresion i want to split with. meth.regexMethHead是我要拆分的常规表达式。
the output given is the next one: 给定的输出是下一个:
Metodos Contenido [0]: Metodos Contenido [0]:
Metodos Contenido [1]: {lol;} Metodos Contenido [1]:{lol;}
Metodos Contenido [2]: {lol;}} Metodos Contenido [2]:{lol;}}
the output wanted is: 所需的输出是:
Metodos Contenido [0]: {lol;} Metodos Contenido [0]:{lol;}
Metodos Contenido [1]: {lol;}} Metodos Contenido [1]:{lol;}}
Regex used 正则表达式使用
Regex used: 使用的正则表达式:
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;
Input String 输入字符串
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+"";
Keep in mind my regex and String come from other class and im pulling them to make the split in another class 请记住,我的正则表达式和String来自其他类,并且我将它们拉到另一个类中进行拆分
THANKS 谢谢
我意识到,当您要拆分时,如果要拆分的表达式以REGEX中的某个值开头,则它假定那里有东西(在正则表达式用于拆分之前),因此这就是为什么要保存为空的原因一开始的空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.