这个不用正则表达式,用字符串index关键字,再找后面几个字符就可以了
比如取得port:
String str = "oracle=....";
int portIndex =str.indexOf("port");
String port = str.substring(portIndex+5,portIndex+9);

解决方案 »

  1.   

    Pattern.parse("oracle\\\\192\\.168\\.10\\.\\\\1521\\\\orcl");
      

  2.   

    to gdsean(摇滚java):
    这种方式不好,我有很多组要取出来,而不是只有一组。to billh2003(比尔):
    不解你的意思。
     
    Thank you anyway.
      

  3.   

    orical开头     ^[a-zA-Z]+\\      
    HOST     [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}   PORT      \\[0-9]+\\SERVICE_NAME    \\[a-zA-Z]+
    自己把反斜杠去掉(ip)不用去。jdk 1。4http://java.sun.com/docs/books/tutorial/extra/regex/index.html给分啊
      

  4.   

    import java.io.*;
    import java.util.regex.*;/**
     *  Description of the Class
     *
     *@author     Administrator
     *@created    2003?¨?6??8??
     */
    public final class RegexTestHarness {    private static String REGEX;
        private static String INPUT;
        private static BufferedReader br;
        private static Pattern pattern;
        private static Matcher matcher;
        private static boolean found;
        /**
         *  The main program for the RegexTestHarness class
         *
         *@param  argv  The command line arguments
         */
        public static void main(String[] argv) {
            initResources();
            processTest();
            closeResources();
        }
        /**
         *  Description of the Method
         */
        private static void initResources() {
            try {
                br = new BufferedReader(new FileReader("regex.txt"));
            } catch (FileNotFoundException fnfe) {
                System.out.println("Cannot locate input file! " + fnfe.getMessage());
                System.exit(0);
            }
            try {
                REGEX = br.readLine();
                INPUT = br.readLine();
            } catch (IOException ioe) {}        pattern = Pattern.compile(REGEX);
            matcher = pattern.matcher(INPUT);        System.out.println("Current REGEX is: " + REGEX);
            System.out.println("Current INPUT is: " + INPUT);
        }
        /**
         *  Description of the Method
         */
        private static void processTest() {
            while (matcher.find()) {
                System.out.println("I found the text \"" + matcher.group() +
                        "\" starting at index " + matcher.start() +
                        " and ending at index " + matcher.end() + ".");
                System.out.println(INPUT.substring(matcher.start(), matcher.end()));
                found = true;
            }        if (!found) {
                System.out.println("No match found.");
            }
        }
        /**
         *  Description of the Method
         */
        private static void closeResources() {
            try {
                br.close();
            } catch (IOException ioe) {}
        }
    }
    是我操的的代码建立regex.txt,写入如下二行,第一行为正则表达,自己运行看吧
    \\[0-9]+\\
    oracle\192.168.10.1\1521\orcl
      

  5.   

    更正
    SERVICE_NAME  用  [a-zA-Z]+$    找
      

  6.   

    现在我是先用下面的方法把它转为普通的String,再对String 做分析,但应该有更好的方法。算了,结贴。
      //只取需要的character
      public static String removeSpaceNPunctuation(String str) {
        Matcher m = Pattern.compile("[\\d\\w\\(\\)\\.\\=]+").matcher(str);
        StringBuffer f = new StringBuffer();
        while (m.find()) {
          f.append(m.group());
        }
        return f.toString();
      }