Compile failed: while( matcher?.find()! ) { .... }

I have to prepare another val before using in while statement :

// translated from java code.

public fun compute(){
  var patternString = path
  patternString = customRegexPattern.replacer(“{<[^/]+>$1}”)?.replace(patternString)!!
  val matcher = argsPattern.matcher(patternString)
// assign it to a val first
  var b = matcher?.find()!!
// now it’s ok
  while(b) {
           args.put(matcher?.group(2)!!, null)
           b = matcher?.find()!!
  }
  patternString = argsPattern.replacer(“({$2}$1)”)?.replace(patternString)!!
  pattern = Pattern(patternString)
  }

It’s not a big problem , just a little unconvenient!

outersky

Why not just something like this ?

  val pattern = Pattern.compile("[0-9]+")   val m = pattern?.matcher("1121 141312 123")!!

  while(m.find()) {
  println(m.group())
  }

ar... Yes! Thanks :p