带有字母和æ,ø,å

时间:2015-07-22 08:09:47

标签: html regex forms

我正在尝试为我的HTML输入表单编写一个模式。我需要接受所有字母(大写和小写),包括特殊字符æ,ø和å(和Æ,Ø,Å)。我还需要接受“ - ”和空白。

2 个答案:

答案 0 :(得分:2)

您可以使用字符类来定义接受的字符。 public void run() { //load properties Properties pro = new Properties(); FileSystem fs = null; try { pro.load(FlinkMain.class.getResourceAsStream("/config.properties")); fs = FileSystem.get(new URI(pro.getProperty("hdfs.namenode")),new org.apache.hadoop.conf.Configuration()); } catch (Exception e) { e.printStackTrace(); } int maxIteration = Integer.parseInt(pro.getProperty("maxiterations")); String outputPath = fs.getHomeDirectory()+pro.getProperty("flink.output"); // set up execution environment ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); // get input points DataSet<GeoTimeDataTupel> points = getPointDataSet(env); DataSet<GeoTimeDataCenter> centroids = null; try { centroids = getCentroidDataSet(env); } catch (Exception e1) { e1.printStackTrace(); } // set number of bulk iterations for KMeans algorithm IterativeDataSet<GeoTimeDataCenter> loop = centroids.iterate(maxIteration); DataSet<GeoTimeDataCenter> newCentroids = points // compute closest centroid for each point .map(new SelectNearestCenter(this.getBenchmarkCounter())).withBroadcastSet(loop, "centroids") // count and sum point coordinates for each centroid .groupBy(0).reduceGroup(new CentroidAccumulator()) // compute new centroids from point counts and coordinate sums .map(new CentroidAverager(this.getBenchmarkCounter())); // feed new centroids back into next iteration with termination condition DataSet<GeoTimeDataCenter> finalCentroids = loop.closeWith(newCentroids, newCentroids.join(loop).where("*").equalTo("*").filter(new MyFilter())); DataSet<Tuple2<Integer, GeoTimeDataTupel>> clusteredPoints = points // assign points to final clusters .map(new SelectNearestCenter(-1)).withBroadcastSet(finalCentroids, "centroids"); // emit result clusteredPoints.writeAsCsv(outputPath+"/points", "\n", " "); finalCentroids.writeAsText(outputPath+"/centers");//print(); // execute program try { env.execute("KMeans Flink"); } catch (Exception e) { e.printStackTrace(); } } public static final class MyFilter implements FilterFunction<Tuple2<GeoTimeDataCenter, GeoTimeDataCenter>> { private static final long serialVersionUID = 5868635346889117617L; public boolean filter(Tuple2<GeoTimeDataCenter, GeoTimeDataCenter> tuple) throws Exception { if(tuple.f0.equals(tuple.f1)) { return true; } else { return false; } } } 。其中,^[a-zA-ZæøåÆØÅ\s\-]*$a-z是标准英文字母,然后是您想要的额外字符。您可以通过使用不区分大小写的标记来避免重复区分大小写的字符。

或者,您可以对所有字母使用Unicode字母字符类,包括其他语言的特殊字符。 A-Z

答案 1 :(得分:0)

感谢你们的时间,但我发现“^ [a-zA-Z-æøåÆØÅ] + $”的工作方式与我想的完全一样。