Java Regex with Sets [x,a-b-c,z,b-c,e,f]

时间:2015-11-18 14:03:13

标签: java regex

我正在收集一些值:

Set's value:
[x, a-b-c, z, b-c, e, f]

所以现在,我通过它迭代来提取一些值:

while (iterator.hasNext()) {
       String Parameter = iterator.next().toString();
       if (Pattern.compile(“Regex??”).matcher(Parameter).find()) {
       do....

这是我被困的地方:

What is the correct Regex to find an exact match for a-b-c 
and the Regex to match for b-c.

if(Pattern.compile(“Regex to find a-b-c”)。matcher(Parameter).find()){ 做 }

if(Pattern.compile(“Regex to find b-c”)。matcher(Parameter).find()){ 做 }

1 个答案:

答案 0 :(得分:2)

我建议您按顺序使用锚点进行完全匹配。

val

trait FooM {
  type A
  val foo: String = implicitly[TypeCls[A]].foo
}

// end of external fixed API

class FooP[A:TypeCls] { // with type params, we can use context bound
  val foo: String = implicitly[TypeCls[A]].foo
}

匹配方法。

^a-b-c$