[英]split a string based on a typical condition in java?
My input string is as follows :我的输入字符串如下:
String sample1 = "productName/@languageCode";
String sample1="brandNameInformation/languageSpecificBrandName/@languageCode";
I want to split it only when there is occurence of "/" and not when "/@"我只想在出现“/”而不是“/@”时拆分它
how can i do it?我该怎么做? can anyone help?有人可以帮忙吗?
You can use negative lookahead :您可以使用负前瞻:
import java.util.Arrays;
public class Main16 {
public static void main(String[] args) {
String sample1 = "productName/@languageCode";
String sample2 ="brandNameInformation/languageSpecificBrandName/@languageCode";
String regex = "/(?!@)";
System.out.println(Arrays.deepToString(sample1.split(regex)));
System.out.println(Arrays.deepToString(sample2.split(regex)));
}
}
output:输出:
[productName/@languageCode]
[brandNameInformation, languageSpecificBrandName/@languageCode]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.