Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**
     * 
     * @param stringToParse
     *            The format of string is : <String>="<String>"
     * @return The second String contained in the stringToParse
     * @throws Exception
     */
    public static String getValue(String stringToParse) throws Exception {
        // Validate the format
        if (!"".equals(applyRegex(stringToParse, ".*=\".*\""))) {
            // System.out.println("parse ok");
            stringToParse = stringToParse.split("=")[1];
            stringToParse = stringToParse.replace("\"", "");
            // System.out.println(stringToParse);
            return stringToParse;
        } else {
            // System.out.println("parse failed");
            return "";
        }

    }

    /**
     * Apply a regex on a String
     * 
     * @param stringToParse
     * @param regex
     * @return The result of the regex
     * @throws Exception
     */
    public static String applyRegex(String stringToParse, String regex) throws Exception {
        // String issue = execute(issueRestUrl);
        /**
         * Qui fonctionnent : - (?<=<[\\/?]?)\\w+(?::\\w+)? : retourne le tag - classname=\"(.*?)\" : retourne l'attribut et se valeur
         */
        // System.out.println("Tested string : " + stringToParse);
        // String regex = "classname=\"(.*?)\"";
        // .*\"status\":\\{.*?\"name\":\"(.*?)\".*?\\}.*
        // .?[a-z]*\"
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(stringToParse);

        if (m.find()) {
            return m.group();
        } else {
            return "";
        }

    }
}