我想从给定字符串中提取数据,我已设法这样做但我遇到了一些困难。
我会给你两个字符串:
"ESS23300RGR","Boorum & Pease 23 Series Columnar Book, Record, 300 Page, Black/Red (23-300-R)","UnbeatableSale, Inc (Amazon Marketplace)","180.80","6.09","http://www.amazon.com/gp/offer-listing/B000DLBVU4/ref=olp_page_next?ie=UTF8&shipPromoFilter=0&startIndex=15&sort=sip&me=&condition=new","http://www.amazon.com/gp/offer-listing/B000DLBVU4/ref=olp_page_next?ie=UTF8&shipPromoFilter=0&startIndex=15&sort=sip&me=&condition=new"
"WLJ36210WGR","Basic Round Ring View Binder, 362 Line, 3 Ring, 1" Capacity, 8-1/2" x 5-1/2" Sheet Size, White","Gov Group (Amazon Marketplace)","3.61","7.70","http://www.amazon.com/gp/offer-listing/B0006OF55A/ref=olp_seeall_fm?ie=UTF8&shipPromoFilter=0&startIndex=0&sort=sip&me=&condition=new","http://www.amazon.com/gp/offer-listing/B0006OF55A/ref=olp_seeall_fm?ie=UTF8&shipPromoFilter=0&startIndex=0&sort=sip&me=&condition=new"
这是我用过的表达式:regexChecker(“[\ w \ s& \(\) - ^,] {3,}”,longString);
使用它我已经设法完美地分离了第一个字符串而第二个字符串没有,因为它使用了,并且“作为某些部分的一部分。
如何从类似于第一个字符串的第二个字符串中提取数据?
需要提取的数据是:SKU,名称,竞争对手,价格,运输,URL,SourceURL
提前致谢。
答案 0 :(得分:3)
尝试:
String[] tabS = myLine.substring(1, myLine.lenght() -1).split("\",\"");
删除所有重要的"
答案 1 :(得分:0)
检查以下代码。它给了我两个输入字符串的预期结果。
StringBuilder testt = new StringBuilder("\"ESS23300RGR\",\"Boorum & Pease 23 Series Columnar Book, Record, 300 Page, Black/Red (23-300-R)\",\"UnbeatableSale, Inc (Amazon Marketplace)\",\"180.80\",\"6.09\",\"http://rads.stackoverflow.com/amzn/click/B000DLBVU4\",\"http://rads.stackoverflow.com/amzn/click/B000DLBVU4\"");
Pattern varPattern = Pattern.compile(",\"", Pattern.CASE_INSENSITIVE);
Matcher varMatcher = varPattern.matcher(testt);
List<String> list = new ArrayList<String>();
int startIndex = 0, endIndex = 0;
boolean found = false;
while (varMatcher.find()) {
endIndex = varMatcher.start();
if (startIndex == 0) {
list.add(testt.substring(startIndex, endIndex));
} else {
list.add(testt.substring(startIndex + 1, endIndex));
}
startIndex = varMatcher.start();
found = true;
}
if (found) {
if (startIndex == 0) {
list.add(testt.substring(startIndex));
} else {
list.add(testt.substring(startIndex + 1));
}
}
for (String s : list) {
System.out.println(s);
}
}