Java File Find find(String _sSourceString, String _sReg, int group)

Here you can find the source of find(String _sSourceString, String _sReg, int group)

Description

find

License

Open Source License

Declaration

public static String find(String _sSourceString, String _sReg, int group) 

Method Source Code


//package com.java2s;

import java.io.UnsupportedEncodingException;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    public static String find(String _sSourceString, String _sReg) {
        return find(_sSourceString, _sReg, 0);
    }//from w  ww  .  j a  v a  2  s.c o m

    public static String find(String _sSourceString, String _sReg, String _sInputEncode, String _sOutEncode) {
        return find(_sSourceString, _sReg, 0, "GBK", "GBK");
    }

    public static String find(String _sSourceString, String _sReg, int group) {
        return find(_sSourceString, _sReg, group, "GBK", "GBK");
    }

    /**
     * @param _sSourceString
     * @param _sReg
     * @param _sInputEncode
     * @param _sOutEncode
     * @return
     */
    public static String find(String _sSourceString, String _sReg, int group, String _sInputEncode,
            String _sOutEncode) {
        if (_sSourceString == null || _sReg == null) {
            return null;
        }
        Matcher mat = Pattern.compile(_sReg).matcher(_sSourceString);
        if (mat.find()) {
            String result = mat.group(group);
            try {
                return new String(result.getBytes(_sInputEncode), _sOutEncode);
            } catch (UnsupportedEncodingException ex) {
                //logger.error("Invalid encoding!", ex);
            }
        }
        return null;
    }
}

Related

  1. find(File folder, final String name)
  2. find(File path, Boolean recursive)
  3. find(File root)
  4. find(final File fileDir, final String fileNameRegex)
  5. find(final File root, final String name)
  6. find(String executable, File... dirs)
  7. find(String name, File dir)
  8. find(String path, String matcher)
  9. find(String path, String suffix)