1 /*
2 * Jour - java profiler and monitoring library
3 *
4 * Copyright (C) 2004 Jour team
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21 package net.sf.jour.util;
22
23 //import java.util.ArrayList;
24 import java.util.Vector;
25
26 //import java.util.regex.Matcher;
27 //import java.util.regex.Pattern;
28 //Java1.3
29 import org.apache.regexp.RE;
30
31 /***
32 * @author michaellif
33 *
34 * TODO To change the template for this generated type comment go to
35 * Window - Preferences - Java - Code Style - Code Templates
36 */
37 public class RegExUtil {
38
39 /*
40 public static String[][] match(String input, String regExp) {
41 ArrayList resultList = new ArrayList();
42
43 Pattern pattern = Pattern.compile(regExp);
44 Matcher matcher = pattern.matcher(input);
45
46 while (matcher.find()) {
47 int groupCount = matcher.groupCount();
48 String[] s = new String[groupCount + 1];
49 for (int i = 0; i <= groupCount; i++) {
50 s[i] = matcher.group(i);
51 }
52 resultList.add(s);
53 }
54
55 return (resultList.size() == 0) ? new String[][] {}
56 : (String[][]) resultList.toArray(new String[0][0]);
57 }*/
58
59 public static String[] match(String input, String regExp) {
60 Vector resultList = new Vector();
61 RE regex = new RE(regExp);
62
63 if (regex.match(input)) {
64 for( int i=1; i < regex.getParenCount() ; ++i ) {
65 String s = regex.getParen(i);
66 resultList.add(s);
67 }
68 }
69 return (String[])resultList.toArray(new String[0]);
70 }
71
72 }