Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.json.JSONException;
import org.json.JSONObject;

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

public class Main {
    public static String getContentMathML(String latexMLResponse) {
        String CML_REGEX = "<annotation-xml.*MWS-Query\">(.*)<.annotation-xml>";
        Pattern pattern = Pattern.compile(CML_REGEX, Pattern.DOTALL);

        try {
            JSONObject latexMLJSON = new JSONObject(latexMLResponse);
            String math = latexMLJSON.getString("result");

            Matcher matcher = pattern.matcher(math);
            if (matcher.find()) {
                return matcher.group(1);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
}