Java Regex Int Validate parseInteger(String key, String sourceString)

Here you can find the source of parseInteger(String key, String sourceString)

Description

parse Integer

License

Open Source License

Declaration

public static Integer parseInteger(String key, String sourceString) 

Method Source Code

//package com.java2s;
/*/*from   w  ww .j  a  va  2s  .  co m*/
 *   Copyright 2008-2011 Follett Software Company 
 *
 *   This file is part of PerfMon4j(tm).
 *
 *    Perfmon4j is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License, version 3,
 *    as published by the Free Software Foundation.  This program is distributed
 *    WITHOUT ANY WARRANTY OF ANY KIND, WITHOUT AN IMPLIED WARRANTY OF MERCHANTIBILITY,
 *    OR FITNESS FOR A PARTICULAR PURPOSE.  You should have received a copy of the GNU Lesser General Public 
 *    License, Version 3, along with this program.  If not, you can obtain the LGPL v.s at 
 *    http://www.gnu.org/licenses/
 *    
 *    perfmon4j@fsc.follett.com
 *    David Deuchert
 *    Follett Software Company
 *    1391 Corporate Drive
 *    McHenry, IL 60050
 * 
*/

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

public class Main {
    public static Integer parseInteger(String key, String sourceString) {
        Integer result = null;
        if (sourceString != null) {
            Pattern pattern = Pattern.compile(quoteForRegEx(key) + "=(\\d++)");
            Matcher matcher = pattern.matcher(sourceString);
            if (matcher.find()) {
                result = new Integer(matcher.group(1));
            }
        }
        return result;
    }

    private static String quoteForRegEx(String input) {
        return "\\Q" + input + "\\E";
    }
}

Related

  1. parseInt(Object str)
  2. parseInt(String value)
  3. parseInt(String[] strs)
  4. parseInteger(String attrVal)
  5. parseInteger(String inStr, Integer def)
  6. parseInteger(String str)
  7. parseIntegerList(String var0, int var1, int var2)
  8. parseIntegers(String integerString)
  9. parseIntToString(String value)