List of usage examples for java.util.regex Pattern compile
public static Pattern compile(String regex)
From source file:com.gzj.tulip.jade.statement.SystemInterpreter.java
public static void main(String[] args) throws Exception { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("table", "my_table_name"); parameters.put("id", "my_id"); parameters.put(":1", "first_param"); final Pattern PATTERN = Pattern.compile("\\{([a-zA-Z0-9_\\.\\:]+)\\}|##\\((.+)\\)"); String sql = "select form ##(:table) {name} where {id}='{1}'"; StringBuilder sb = new StringBuilder(sql.length() + 200); Matcher matcher = PATTERN.matcher(sql); int start = 0; while (matcher.find(start)) { sb.append(sql.substring(start, matcher.start())); String group = matcher.group(); String key = null;/* w w w . j a v a 2 s . c om*/ if (group.startsWith("{")) { key = matcher.group(1); } else if (group.startsWith("##(")) { key = matcher.group(2); } System.out.println(key); if (key == null || key.length() == 0) { continue; } Object value = parameters.get(key); // {paramName}?{:1}? if (value == null) { if (key.startsWith(":") || key.startsWith("$")) { value = parameters.get(key.substring(1)); // {:paramName} } else { char ch = key.charAt(0); if (ch >= '0' && ch <= '9') { value = parameters.get(":" + key); // {1}? } } } if (value == null) { value = parameters.get(key); // ? } if (value != null) { sb.append(value); } else { sb.append(group); } start = matcher.end(); } sb.append(sql.substring(start)); System.out.println(sb); }
From source file:it.unipd.dei.ims.falcon.CmdLine.java
public static void main(String[] args) { // last argument is always index path Options options = new Options(); // one of these actions has to be specified OptionGroup actionGroup = new OptionGroup(); actionGroup.addOption(new Option("i", true, "perform indexing")); // if dir, all files, else only one file actionGroup.addOption(new Option("q", true, "perform a single query")); actionGroup.addOption(new Option("b", false, "perform a query batch (read from stdin)")); actionGroup.setRequired(true);/*ww w . ja v a 2s . c o m*/ options.addOptionGroup(actionGroup); // other options options.addOption(new Option("l", "segment-length", true, "length of a segment (# of chroma vectors)")); options.addOption( new Option("o", "segment-overlap", true, "overlap portion of a segment (# of chroma vectors)")); options.addOption(new Option("Q", "quantization-level", true, "quantization level for chroma vectors")); options.addOption(new Option("k", "min-kurtosis", true, "minimum kurtosis for indexing chroma vectors")); options.addOption(new Option("s", "sub-sampling", true, "sub-sampling of chroma features")); options.addOption(new Option("v", "verbose", false, "verbose output (including timing info)")); options.addOption(new Option("T", "transposition-estimator-strategy", true, "parametrization for the transposition estimator strategy")); options.addOption(new Option("t", "n-transp", true, "number of transposition; if not specified, no transposition is performed")); options.addOption(new Option("f", "force-transp", true, "force transposition by an amount of semitones")); options.addOption(new Option("p", "pruning", false, "enable query pruning; if -P is unspecified, use default strategy")); options.addOption(new Option("P", "pruning-custom", true, "custom query pruning strategy")); // parse HelpFormatter formatter = new HelpFormatter(); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.getArgs().length != 1) throw new ParseException("no index path was specified"); } catch (ParseException ex) { System.err.println("ERROR - parsing command line:"); System.err.println(ex.getMessage()); formatter.printHelp("falcon -{i,q,b} [options] index_path", options); return; } // default values final float[] DEFAULT_TRANSPOSITION_ESTIMATOR_STRATEGY = new float[] { 0.65192807f, 0.0f, 0.0f, 0.0f, 0.3532628f, 0.4997167f, 0.0f, 0.41703504f, 0.0f, 0.16297342f, 0.0f, 0.0f }; final String DEFAULT_QUERY_PRUNING_STRATEGY = "ntf:0.340765*[0.001694,0.995720];ndf:0.344143*[0.007224,0.997113];" + "ncf:0.338766*[0.001601,0.995038];nmf:0.331577*[0.002352,0.997884];"; // TODO not the final one int hashes_per_segment = Integer.parseInt(cmd.getOptionValue("l", "150")); int overlap_per_segment = Integer.parseInt(cmd.getOptionValue("o", "50")); int nranks = Integer.parseInt(cmd.getOptionValue("Q", "3")); int subsampling = Integer.parseInt(cmd.getOptionValue("s", "1")); double minkurtosis = Float.parseFloat(cmd.getOptionValue("k", "-100.")); boolean verbose = cmd.hasOption("v"); int ntransp = Integer.parseInt(cmd.getOptionValue("t", "1")); TranspositionEstimator tpe = null; if (cmd.hasOption("t")) { if (cmd.hasOption("T")) { // TODO this if branch is yet to test Pattern p = Pattern.compile("\\d\\.\\d*"); LinkedList<Double> tokens = new LinkedList<Double>(); Matcher m = p.matcher(cmd.getOptionValue("T")); while (m.find()) tokens.addLast(new Double(cmd.getOptionValue("T").substring(m.start(), m.end()))); float[] strategy = new float[tokens.size()]; if (strategy.length != 12) { System.err.println("invalid transposition estimator strategy"); System.exit(1); } for (int i = 0; i < strategy.length; i++) strategy[i] = new Float(tokens.pollFirst()); } else { tpe = new TranspositionEstimator(DEFAULT_TRANSPOSITION_ESTIMATOR_STRATEGY); } } else if (cmd.hasOption("f")) { int[] transps = parseIntArray(cmd.getOptionValue("f")); tpe = new ForcedTranspositionEstimator(transps); ntransp = transps.length; } QueryPruningStrategy qpe = null; if (cmd.hasOption("p")) { if (cmd.hasOption("P")) { qpe = new StaticQueryPruningStrategy(cmd.getOptionValue("P")); } else { qpe = new StaticQueryPruningStrategy(DEFAULT_QUERY_PRUNING_STRATEGY); } } // action if (cmd.hasOption("i")) { try { Indexing.index(new File(cmd.getOptionValue("i")), new File(cmd.getArgs()[0]), hashes_per_segment, overlap_per_segment, subsampling, nranks, minkurtosis, tpe, verbose); } catch (IndexingException ex) { Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex); } } if (cmd.hasOption("q")) { String queryfilepath = cmd.getOptionValue("q"); doQuery(cmd, queryfilepath, hashes_per_segment, overlap_per_segment, nranks, subsampling, tpe, ntransp, minkurtosis, qpe, verbose); } if (cmd.hasOption("b")) { try { long starttime = System.currentTimeMillis(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line = null; while ((line = in.readLine()) != null && !line.trim().isEmpty()) doQuery(cmd, line, hashes_per_segment, overlap_per_segment, nranks, subsampling, tpe, ntransp, minkurtosis, qpe, verbose); in.close(); long endtime = System.currentTimeMillis(); System.out.println(String.format("total time: %ds", (endtime - starttime) / 1000)); } catch (IOException ex) { Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex); } } }
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//from w w w . j a v a 2 s . c o m .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(); String group = matcher.group("postunit"); System.out.println(group); }
From source file:com.roncoo.pay.permission.utils.ValidateUtils.java
public static void main(String[] args) { String url = "http://192.168.88.106:8082/roncoo-web-gateway/bankPaySuccess_paySuccess.action"; // String url = // "http://192.168.88.247:8088/roncoo-web-shop/Xotify_url.jsp"; Pattern pattern = Pattern // .compile(""); .compile(/*from w w w .j ava 2 s .c om*/ "^(https?|ftp):\\/\\/(((([a-z]|[A-Z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:)*@)?(((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]))|((([a-z]|[A-Z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|[A-Z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|[A-Z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|[A-Z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.)+(([a-z]|[A-Z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|[A-Z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|[A-Z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|[A-Z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.?)(:\\d*)?)(\\/((([a-z]|[A-Z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)+(\\/(([a-z]|[A-Z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)*)*)?)?(\\?((([a-z]|[A-Z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)|[\\uE000-\\uF8FF]|\\/|\\?)*)?(\\#((([a-z]|[A-Z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)|\\/|\\?)*)?$"); Boolean bool = pattern.matcher(url).matches(); System.out.println(bool); }
From source file:edu.uci.mhlee.BasicCrawler.java
public static void main(String[] args) { String href = "http://aaaa/?alskdjfalk=10"; String[] aaa = href.split("(\\?.*)?$"); System.out.println(aaa[0]);/*from w w w .j av a2 s . c o m*/ System.out.println(aaa.length); Pattern URL_QUERY = Pattern.compile(".*\\.(\\?.*)?$"); System.out.println(URL_QUERY.matcher(href).matches()); System.out.println(href.contains("?")); }
From source file:Main.java
public static boolean isTel(String tel) { return Pattern.compile("^((13[0-9])|(14[0-9])|(15[0,0-9])|(18[0,0-9]))\\d{8}$").matcher(tel).matches(); }
From source file:Main.java
private static Pattern buildPattern() { return Pattern.compile("\\\\u1f[a-z0-9]{3}"); }
From source file:Main.java
private static void match(String REGEX, String INPUT) { Pattern p = Pattern.compile(REGEX); Matcher m = p.matcher(INPUT); int count = 0; while (m.find()) { count++;/*www . j ava 2s .c o m*/ System.out.println("\nMatch number: " + count); System.out.println("start() : " + m.start()); System.out.println("end() : " + m.end()); System.out.println("group() : " + m.group()); } }
From source file:Main.java
public static boolean isNumeric(String str) { return Pattern.compile("\\d*\\.{0,1}\\d*").matcher(str).matches(); }
From source file:Main.java
public static boolean IsInteger(String str) { return Pattern.compile("-?[0-9]+").matcher(str).matches(); }