List of usage examples for java.util.regex Matcher group
public String group(String name)
From source file:BookRank.java
/** Grab the sales rank off the web page and log it. */ public static void main(String[] args) throws Exception { Properties p = new Properties(); String title = p.getProperty("title", "NO TITLE IN PROPERTIES"); // The url must have the "isbn=" at the very end, or otherwise // be amenable to being string-catted to, like the default. String url = p.getProperty("url", "http://test.ing/test.cgi?isbn="); // The 10-digit ISBN for the book. String isbn = p.getProperty("isbn", "0000000000"); // The RE pattern (MUST have ONE capture group for the number) String pattern = p.getProperty("pattern", "Rank: (\\d+)"); // Looking for something like this in the input: // <b>QuickBookShop.web Sales Rank: </b> // 26,252//from www . j a v a 2 s .c o m // </font><br> Pattern r = Pattern.compile(pattern); // Open the URL and get a Reader from it. BufferedReader is = new BufferedReader(new InputStreamReader(new URL(url + isbn).openStream())); // Read the URL looking for the rank information, as // a single long string, so can match RE across multi-lines. String input = "input from console"; // System.out.println(input); // If found, append to sales data file. Matcher m = r.matcher(input); if (m.find()) { PrintWriter pw = new PrintWriter(new FileWriter(DATA_FILE, true)); String date = // `date +'%m %d %H %M %S %Y'`; new SimpleDateFormat("MM dd hh mm ss yyyy ").format(new Date()); // Paren 1 is the digits (and maybe ','s) that matched; remove comma Matcher noComma = Pattern.compile(",").matcher(m.group(1)); pw.println(date + noComma.replaceAll("")); pw.close(); } else { System.err.println("WARNING: pattern `" + pattern + "' did not match in `" + url + isbn + "'!"); } // Whether current data found or not, draw the graph, using // external plotting program against all historical data. // Could use gnuplot, R, any other math/graph program. // Better yet: use one of the Java plotting APIs. String gnuplot_cmd = "set term png\n" + "set output \"" + GRAPH_FILE + "\"\n" + "set xdata time\n" + "set ylabel \"Book sales rank\"\n" + "set bmargin 3\n" + "set logscale y\n" + "set yrange [1:60000] reverse\n" + "set timefmt \"%m %d %H %M %S %Y\"\n" + "plot \"" + DATA_FILE + "\" using 1:7 title \"" + title + "\" with lines\n"; Process proc = Runtime.getRuntime().exec("/usr/local/bin/gnuplot"); PrintWriter gp = new PrintWriter(proc.getOutputStream()); gp.print(gnuplot_cmd); gp.close(); }
From source file:de.codesourcery.eve.skills.datamodel.EveFlags.java
public static void main(String[] args) { final Pattern PATTERN = Pattern.compile("^([0-9]+),(.*?),(.*)$"); for (String line : FLAGS.split("\n")) { final String trimmed = StringUtils.strip(line); final Matcher m = PATTERN.matcher(line); if (!m.matches()) { throw new RuntimeException(); }/*from w w w . j a va 2s . c om*/ final int id = Integer.parseInt(m.group(1)); final String name = m.group(2).toUpperCase().replaceAll(" ", "_"); final String displayName = StringUtils.strip(m.group(3)); System.out.println(name + "(" + id + ",\"" + displayName + "\"),"); } }
From source file:org.roda.core.common.SeleniumUtils.java
/** * // ww w . j a v a 2s .c om * @param args: * the first argument is the RODA base url and the second argument is * the driver path * @throws InterruptedException * @throws IOException */ public static void main(String[] args) throws InterruptedException, IOException { if (args.length != 2) { System.err.println("Number of arguments not correct since it is only needed two arguments. " + "The first argument is the RODA base url and the second argument is the driver path"); commandHelp(); System.exit(0); } url = args[0]; driverPath = args[1]; ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(new File(driverPath)) .usingAnyFreePort().build(); service.start(); driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); driver.get(url); // welcome page saveHTML(); savePublicPages(); saveLoginPages(); saveHelpPages(); savePlanningPages(); saveAdminPages(); saveIngestPages(); saveSearchPages(); saveBrowsePages(); driver.quit(); service.stop(); for (Entry<String, String> entry : locations.entrySet()) { String location = entry.getKey(); String html = getHTMLSource(location); Pattern expression = Pattern.compile("<div id=\"webaxscore\".*?<span>(.*?)</span>"); Matcher matcher = expression.matcher(html); if (matcher.find()) { System.out.println(location + " | " + locations.get(location) + " | " + matcher.group(1)); } } }
From source file:de.citec.csra.elancsv.parser.SimpleParser.java
public static void main(String[] args) throws IOException, ParseException { Options opts = new Options(); opts.addOption("file", true, "Tab-separated ELAN export file to load."); opts.addOption("tier", true, "Tier to analyze. Optional: Append ::num to interpret annotations numerically."); opts.addOption("format", true, "How to read information from the file name. %V -> participant, %A -> annoatator, %C -> condition, e.g. \"%V - %A\""); opts.addOption("help", false, "Print this help and exit"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(opts, args); if (cmd.hasOption("help")) { helpExit(opts, "where OPTION includes:"); }/*from w w w . j a v a2s .com*/ String infile = cmd.getOptionValue("file"); if (infile == null) { helpExit(opts, "Error: no file given."); } String format = cmd.getOptionValue("format"); if (format == null) { helpExit(opts, "Error: no format given."); } String tier = cmd.getOptionValue("tier"); if (tier == null) { helpExit(opts, "Error: no tier given."); } // TODO count values in annotations (e.g. search all robot occurrences) String[] tn = tier.split("::"); boolean numeric = false; if (tn.length == 2 && tn[1].equals("num")) { numeric = true; tier = tn[0]; } format = "^" + format + "$"; format = format.replaceFirst("%V", "(?<V>.*?)"); format = format.replaceFirst("%A", "(?<A>.*?)"); format = format.replaceFirst("%C", "(?<C>.*?)"); Pattern pa = Pattern.compile(format); Map<String, Participant> participants = new HashMap<>(); BufferedReader br = new BufferedReader(new FileReader(infile)); String line; int lineno = 0; while ((line = br.readLine()) != null) { String[] parts = line.split("\t"); lineno++; if (parts.length < 5) { System.err.println("WARNING: line '" + lineno + "' too short '" + line + "'"); continue; } Annotation a = new Annotation(Long.valueOf(parts[ElanFormat.START.field]), Long.valueOf(parts[ElanFormat.STOP.field]), Long.valueOf(parts[ElanFormat.DURATION.field]), parts[ElanFormat.VALUE.field]); String tname = parts[ElanFormat.TIER.field]; String file = parts[ElanFormat.FILE.field].replaceAll(".eaf", ""); Matcher m = pa.matcher(file); String vp = file; String condition = "?"; String annotator = "?"; String participantID = vp; if (m.find()) { vp = m.group("V"); if (format.indexOf("<A>") > 0) { annotator = m.group("A"); } if (format.indexOf("<C>") > 0) { condition = m.group("C"); } } participantID = vp + ";" + annotator; if (!participants.containsKey(participantID)) { participants.put(participantID, new Participant(vp, condition, annotator)); } Participant p = participants.get(participantID); if (!p.tiers.containsKey(tname)) { p.tiers.put(tname, new Tier(tname)); } p.tiers.get(tname).annotations.add(a); } Map<String, Map<String, Number>> values = new HashMap<>(); Set<String> rownames = new HashSet<>(); String allCountKey = "c: all values"; String allDurationKey = "d: all values"; String allMeanKey = "m: all values"; for (Map.Entry<String, Participant> e : participants.entrySet()) { // System.out.println(e); Tier t = e.getValue().tiers.get(tier); String participantID = e.getKey(); if (!values.containsKey(participantID)) { values.put(participantID, new HashMap<String, Number>()); } Map<String, Number> row = values.get(participantID); //participant id if (t != null) { row.put(allCountKey, 0l); row.put(allDurationKey, 0l); row.put(allMeanKey, 0l); for (Annotation a : t.annotations) { long countAll = (long) row.get(allCountKey) + 1; long durationAll = (long) row.get(allDurationKey) + a.duration; long meanAll = durationAll / countAll; row.put(allCountKey, countAll); row.put(allDurationKey, durationAll); row.put(allMeanKey, meanAll); if (!numeric) { String countKey = "c: " + a.value; String durationKey = "d: " + a.value; String meanKey = "m: " + a.value; if (!row.containsKey(countKey)) { row.put(countKey, 0l); } if (!row.containsKey(durationKey)) { row.put(durationKey, 0l); } if (!row.containsKey(meanKey)) { row.put(meanKey, 0d); } long count = (long) row.get(countKey) + 1; long duration = (long) row.get(durationKey) + a.duration; double mean = duration * 1.0 / count; row.put(countKey, count); row.put(durationKey, duration); row.put(meanKey, mean); rownames.add(countKey); rownames.add(durationKey); rownames.add(meanKey); } else { String countKey = "c: " + t.name; String sumKey = "s: " + t.name; String meanKey = "m: " + t.name; if (!row.containsKey(countKey)) { row.put(countKey, 0l); } if (!row.containsKey(sumKey)) { row.put(sumKey, 0d); } if (!row.containsKey(meanKey)) { row.put(meanKey, 0d); } double d = 0; try { d = Double.valueOf(a.value); } catch (NumberFormatException ex) { } long count = (long) row.get(countKey) + 1; double sum = (double) row.get(sumKey) + d; double mean = sum / count; row.put(countKey, count); row.put(sumKey, sum); row.put(meanKey, mean); rownames.add(countKey); rownames.add(sumKey); rownames.add(meanKey); } } } } ArrayList<String> list = new ArrayList(rownames); Collections.sort(list); StringBuilder header = new StringBuilder("ID;Annotator;"); header.append(allCountKey); header.append(";"); header.append(allDurationKey); header.append(";"); header.append(allMeanKey); header.append(";"); for (String l : list) { header.append(l); header.append(";"); } System.out.println(header); for (Map.Entry<String, Map<String, Number>> e : values.entrySet()) { StringBuilder row = new StringBuilder(e.getKey()); row.append(";"); if (e.getValue().containsKey(allCountKey)) { row.append(e.getValue().get(allCountKey)); } else { row.append("0"); } row.append(";"); if (e.getValue().containsKey(allDurationKey)) { row.append(e.getValue().get(allDurationKey)); } else { row.append("0"); } row.append(";"); if (e.getValue().containsKey(allMeanKey)) { row.append(e.getValue().get(allMeanKey)); } else { row.append("0"); } row.append(";"); for (String l : list) { if (e.getValue().containsKey(l)) { row.append(e.getValue().get(l)); } else { row.append("0"); } row.append(";"); } System.out.println(row); } }
From source file:com.basistech.lucene.tools.LuceneQueryTool.java
public static void main(String[] args) throws IOException, org.apache.lucene.queryparser.classic.ParseException { String charsetName = Charset.defaultCharset().name(); if (!"UTF-8".equals(charsetName)) { // Really only a problem on mac, where the default charset is MacRoman, // and it cannot be changed via the system Locale. System.err.println(String.format("defaultCharset is %s, but we require UTF-8.", charsetName)); System.err.println("Set -Dfile.encoding=UTF-8 on the Java command line, or"); System.err.println("set JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8 in the environment."); System.exit(1);//from w ww. j ava 2 s. c om } Options options = LuceneQueryTool.createOptions(); CommandLineParser parser = new GnuParser(); CommandLine cmdline = null; try { cmdline = parser.parse(options, args); validateOptions(options, args); } catch (org.apache.commons.cli.ParseException e) { System.err.println(e.getMessage()); usage(options); System.exit(1); } String[] remaining = cmdline.getArgs(); if (remaining != null && remaining.length > 0) { System.err.println("unknown extra args found: " + Lists.newArrayList(remaining)); usage(options); System.exit(1); } String[] indexPaths = cmdline.getOptionValues("index"); IndexReader[] readers = new IndexReader[indexPaths.length]; for (int i = 0; i < indexPaths.length; i++) { readers[i] = DirectoryReader.open(FSDirectory.open(new File(indexPaths[i]))); } IndexReader reader = new MultiReader(readers, true); LuceneQueryTool that = new LuceneQueryTool(reader); String opt; opt = cmdline.getOptionValue("query-limit"); if (opt != null) { that.setQueryLimit(Integer.parseInt(opt)); } opt = cmdline.getOptionValue("output-limit"); if (opt != null) { that.setOutputLimit(Integer.parseInt(opt)); } opt = cmdline.getOptionValue("analyzer"); if (opt != null) { that.setAnalyzer(opt); } opt = cmdline.getOptionValue("query-field"); if (opt != null) { that.setDefaultField(opt); } opt = cmdline.getOptionValue("output"); PrintStream out = null; if (opt != null) { out = new PrintStream(new FileOutputStream(new File(opt)), true); that.setOutputStream(out); } if (cmdline.hasOption("show-id")) { that.setShowId(true); } if (cmdline.hasOption("show-hits")) { that.setShowHits(true); } if (cmdline.hasOption("show-score")) { that.setShowScore(true); } if (cmdline.hasOption("sort-fields")) { that.setSortFields(true); } if (cmdline.hasOption("suppress-names")) { that.setSuppressNames(true); } if (cmdline.hasOption("tabular")) { that.setTabular(true); } String[] opts; opts = cmdline.getOptionValues("fields"); if (opts != null) { that.setFieldNames(Lists.newArrayList(opts)); } opt = cmdline.getOptionValue("regex"); if (opt != null) { Pattern p = Pattern.compile("^(.*?):/(.*)/$"); Matcher m = p.matcher(opt); if (m.matches()) { that.setRegex(m.group(1), Pattern.compile(m.group(2))); } else { System.err.println("Invalid regex, should be field:/regex/"); usage(options); System.exit(1); } } opts = cmdline.getOptionValues("query"); that.run(opts); if (out != null) { out.close(); } reader.close(); }
From source file:com.genentech.struchk.oeStruchk.OEStruchk.java
/** * Command line interface to {@link OEStruchk}. *//*from ww w . j a v a 2 s . c o m*/ public static void main(String[] args) throws ParseException, JDOMException, IOException { long start = System.currentTimeMillis(); int nMessages = 0; int nErrors = 0; int nStruct = 0; System.err.printf("OEChem Version: %s\n", oechem.OEChemGetVersion()); // create command line Options object Options options = new Options(); Option opt = new Option("f", true, "specify the configuration file name"); opt.setRequired(false); options.addOption(opt); opt = new Option("noMsg", false, "Do not add any additional sd-tags to the sdf file"); options.addOption(opt); opt = new Option("printRules", true, "Print HTML listing all the rules to filename."); options.addOption(opt); opt = new Option("errorsAsWarnings", false, "Treat errors as warnings."); options.addOption(opt); opt = new Option("stopForDebug", false, "Stop and read from stdin for user tu start debugger."); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); args = cmd.getArgs(); if (cmd.hasOption("stopForDebug")) { BufferedReader localRdr = new BufferedReader(new InputStreamReader(System.in)); System.err.print("Please press return:"); localRdr.readLine(); } URL confFile; if (cmd.hasOption("f")) { confFile = new File(cmd.getOptionValue("f")).toURI().toURL(); } else { confFile = getResourceURL(OEStruchk.class, "Struchk.xml"); } boolean errorsAsWarnings = cmd.hasOption("errorsAsWarnings"); if (cmd.hasOption("printRules")) { String fName = cmd.getOptionValue("printRules"); PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(fName))); OEStruchk structFlagAssigner = new OEStruchk(confFile, CHECKConfig.ASSIGNStructFlag, errorsAsWarnings); structFlagAssigner.printRules(out); out.close(); return; } if (args.length < 1) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("oeStruck", options); throw new Error("missing input file\n"); } BufferedReader in = null; try { in = new BufferedReader(new FileReader(args[0])); StringBuilder mol = new StringBuilder(); StringBuilder data = new StringBuilder(); PrintStream out = System.out; if (args.length > 1) out = new PrintStream(args[1]); // create OEStruchk from config file OEStruchk structFlagAssigner = new OEStruchk(confFile, CHECKConfig.ASSIGNStructFlag, errorsAsWarnings); OEStruchk structFlagChecker = new OEStruchk(confFile, CHECKConfig.CHECKStructFlag, errorsAsWarnings); Pattern sFlagPat = Pattern.compile("<StructFlag>\\s*([^\\n\\r]+)"); String line; boolean inMolFile = true; boolean atEnd = false; while (!atEnd) { if ((line = in.readLine()) == null) { if ("".equals(mol.toString().trim())) break; if (!inMolFile) throw new Error("Invalid end of sd file!"); line = "$$$$"; atEnd = true; } if (line.startsWith("$$$$")) { OEStruchk oeStruchk; StructureFlag sFlag = null; Matcher mat = sFlagPat.matcher(data); if (!mat.find()) { oeStruchk = structFlagAssigner; } else { oeStruchk = structFlagChecker; sFlag = StructureFlag.fromString(mat.group(1)); } if (!oeStruchk.applyRules(mol.toString(), null, sFlag)) nErrors++; out.print(oeStruchk.getTransformedMolfile(null)); out.print(data); if (!cmd.hasOption("noMsg")) { List<Message> msgs = oeStruchk.getStructureMessages(null); if (msgs.size() > 0) { nMessages += msgs.size(); out.println("> <errors_oe2>"); for (Message msg : msgs) out.printf("%s: %s\n", msg.getLevel(), msg.getText()); out.println(); } //System.err.println(oeStruchk.getTransformedMolfile("substance")); out.printf("> <outStereo>\n%s\n\n", oeStruchk.getStructureFlag().getName()); out.printf("> <TISM>\n%s\n\n", oeStruchk.getTransformedIsoSmiles(null)); out.printf("> <TSMI>\n%s\n\n", oeStruchk.getTransformedSmiles(null)); out.printf("> <pISM>\n%s\n\n", oeStruchk.getTransformedIsoSmiles("parent")); out.printf("> <salt>\n%s\n\n", oeStruchk.getSaltCode()); out.printf("> <stereoCounts>\n%s.%s\n\n", oeStruchk.countChiralCentersStr(), oeStruchk.countStereoDBondStr()); } out.println(line); nStruct++; mol.setLength(0); data.setLength(0); inMolFile = true; } else if (!inMolFile || line.startsWith(">")) { inMolFile = false; data.append(line).append("\n"); } else { mol.append(line).append("\n"); } } structFlagAssigner.delete(); structFlagChecker.delete(); } catch (Exception e) { throw new Error(e); } finally { System.err.printf("Checked %d structures %d errors, %d messages in %dsec\n", nStruct, nErrors, nMessages, (System.currentTimeMillis() - start) / 1000); if (in != null) in.close(); } if (cmd.hasOption("stopForDebug")) { BufferedReader localRdr = new BufferedReader(new InputStreamReader(System.in)); System.err.print("Please press return:"); localRdr.readLine(); } }
From source file:br.on.daed.services.horizons.HttpConnector.java
public static void main(String args[]) { Pattern compile = Pattern.compile( "(?:^|\\s*)(?:Mass[^(]*\\(?)(?<unit>[0-9^]+)?(?:[^=~]*(?:=|~)\\s*)(?<mass>[0-9.,E]+)(?:\\s*)(?:\\((?!.*\\+-)(?<postunit>.*\\^.*)\\))?"); Matcher matcher = compile .matcher("*******************************************************************************\n" + " Revised: Sep 28, 2012 Deimos / (Mars) 402\n" + "\n" + " SATELLITE PHYSICAL PROPERTIES:\n" + " Radius (km) = 7.8 x 6.0 x 5.1 Density (g cm^-3) = 1.76 +- 0.30\n" + " Mass (10^20 kg ) = 1.80 (10^-5) Geometric Albedo = 0.06 \n" + " (+- 0.15) V(1,0) = +12.89\n" + "\n" + " SATELLITE ORBITAL DATA:\n" + " Semi-major axis, a (km) = 23.4632(10^3) Orbital period = 1.263 d\n" + " Eccentricity, e = 0.00033 Rotational period = Synchronous\n" + " Inclination, i (deg) = 1.791\n" + "*******************************************************************************\n" + " \n" + " \n" + "*******************************************************************************\n" + "Ephemeris / WWW_USER Thu Aug 25 13:58:15 2016 Pasadena, USA / Horizons \n" + "*******************************************************************************\n" + "Target body name: Deimos (402) {source: mar097}\n" + "Center body name: Sun (10) {source: mar097}\n" + "Center-site name: BODY CENTER\n" + "*******************************************************************************\n" + "Start time : A.D. 2000-Jan-01 00:00:00.0000 TDB\n" + "Stop time : A.D. 2000-Jan-02 00:00:00.0000 TDB\n" + "Step-size : 597600 minutes\n" + "*******************************************************************************\n" + "Center geodetic : 0.00000000,0.00000000,0.0000000 {E-lon(deg),Lat(deg),Alt(km)}\n" + "Center cylindric: 0.00000000,0.00000000,0.0000000 {E-lon(deg),Dxy(km),Dz(km)}\n" + "Center radii : 696000.0 x 696000.0 x 696000.0 k{Equator, meridian, pole} \n" + "System GM : 2.9591220828559109E-04 au^3/d^2\n" + "Output units : AU-D, deg, Julian day number (Tp) \n" + "Output format : 10\n" + "Reference frame : ICRF/J2000.0 \n" + "Output type : GEOMETRIC osculating elements\n" + "Coordinate systm: Ecliptic and Mean Equinox of Reference Epoch \n" + "*******************************************************************************\n" + "JDTDB\n" + " EC QR IN\n" + " OM W Tp\n" + " N MA TA\n" + " A AD PR\n" + "*******************************************************************************\n" + "$$SOE\n" + "2451544.500000000 = A.D. 2000-Jan-01 00:00:00.0000 (TDB)\n" + " EC= 2.326887802497893E-02 QR= 1.337811007124899E+00 IN= 2.139216386111699E+00\n" + " OM= 4.083435138741744E+01 W = 1.857454986387542E+02 Tp= 2451332.176361185033\n" + " N = 6.148574868705978E-01 MA= 1.305487789649286E+02 TA= 1.325368384195841E+02\n" + " A = 1.369681969813503E+00 AD= 1.401552932502106E+00 PR= 5.855015311471115E+02\n" + "$$EOE\n" + "*******************************************************************************\n" + "Coordinate system description:\n" + "\n" + " Ecliptic and Mean Equinox of Reference Epoch\n" + "\n" + " Reference epoch: J2000.0\n" + " xy-plane: plane of the Earth's orbit at the reference epoch\n" + " x-axis : out along ascending node of instantaneous plane of the Earth's\n" + " orbit and the Earth's mean equator at the reference epoch\n" + " z-axis : perpendicular to the xy-plane in the directional (+ or -) sense\n" + " of Earth's north pole at the reference epoch.\n" + "\n" + "Symbol meaning [1 au=149597870.700 km, 1 day=86400.0 s]:\n" + "\n" + " JDTDB Epoch Julian Date, Barycentric Dynamical Time\n" + " EC Eccentricity, e \n" + " QR Periapsis distance, q (AU) \n" + " IN Inclination w.r.t xy-plane, i (degrees) \n" + " OM Longitude of Ascending Node, OMEGA, (degrees) \n" + " W Argument of Perifocus, w (degrees) \n" + " Tp Time of periapsis (Julian day number) \n" + " N Mean motion, n (degrees/day) \n" + " MA Mean anomaly, M (degrees) \n" + " TA True anomaly, nu (degrees) \n" + " A Semi-major axis, a (AU) \n" + " AD Apoapsis distance (AU) \n" + " PR Sidereal orbit period (day) \n" + "\n" + "Geometric states/elements have no aberration corrections applied.\n" + "\n" + " Computations by ...\n" + " Solar System Dynamics Group, Horizons On-Line Ephemeris System\n" + " 4800 Oak Grove Drive, Jet Propulsion Laboratory\n" + " Pasadena, CA 91109 USA\n" + " Information: http://ssd.jpl.nasa.gov/\n" + " Connect : telnet://ssd.jpl.nasa.gov:6775 (via browser)\n" + " telnet ssd.jpl.nasa.gov 6775 (via command-line)\n" + " Author : Jon.Giorgini@jpl.nasa.gov\n" + "*******************************************************************************\n" + "\n" + "!$$SOF\n" + "OBJ_DATA = YES\n" + "CENTER = 10\n" + "COMMAND = 402\n" + "MAKE_EPHEM = YES\n" + "OUT_UNITS = AU-D\n" + "TABLE_TYPE = ELEM\n" + "START_TIME = JD2451544.5\n" + "STOP_TIME = JD2451545.5\n" + "STEP_SIZE = 415d"); matcher.find();/*www.ja v a2s . co m*/ String group = matcher.group("postunit"); System.out.println(group); }
From source file:Main.java
private static String runSubRegex(String regex, String tag) { Pattern p = Pattern.compile(regex); Matcher matcher = p.matcher(tag); if (matcher.find()) { return matcher.group(1); }/*from w w w.java 2 s . co m*/ return null; }
From source file:Main.java
public static int getNumber(String s1) throws Exception { Pattern pattern = Pattern.compile("([\\-0-9]*)[,]*.*"); Matcher m = pattern.matcher(s1); if (m.find()) { return Integer.parseInt(m.group(1)); }/*w ww.ja v a 2 s. co m*/ throw new Exception("Not valid input"); }
From source file:Main.java
public static String getParameterFromUrl(String param, String url) { Pattern p = Pattern.compile(param + "=([^&]+)"); Matcher m = p.matcher(url); m.find();/*from w w w . ja v a2 s . co m*/ return m.group(1); }