Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.net.URLDecoder;

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

public class Main {
    /**
     * Extracts a desired string given a string and a pattern using regex
     * 
     * @param response the string to extract from
     * @param pattern the regex pattern used to extract 
     * 
     * @return desired extracted string
     */
    @SuppressWarnings("deprecation")
    public static String extract(String response, Pattern pattern) {
        String extraction = null;
        Matcher matcher = pattern.matcher(response);
        if (matcher.find() && matcher.groupCount() >= 1) {
            extraction = URLDecoder.decode(matcher.group(1));
        }
        return extraction;
    }
}