-5

我正在尝试使用 java regex 提取一个看起来像这样(如下)的字符串。

Automotive Vehicles  (154949)

Cars  (91364)

Auto Parts & Accessories  (29987)

Motorcycles & Scooters  (11648)

我尝试了以下方法:

for (Element link : links) {
    String cat = link.text();
    String pattern = "(\\w+\\w+?\\s?.?\\w+)";
    Pattern p = Pattern.compile(pattern);
    Matcher m = p.matcher(cat);
    while (m.find( )) {
        System.out.println("Category: "+m.group(0));         
    } 
}
4

1 回答 1

0

使用 vim 正则表达式提取文本和数字

\(.*\)(\(\d*\))

第 1 组是文字,第 2 组是数字

所以..自从我在 Java 中完成 RegEx 已经有一段时间了,但我认为它:

(.*)\((\d+)\)
于 2013-11-05T09:56:31.870 回答