/ / защо е невъзможно тази мащабна папка с регекс? - регекс, скала

защо тази мащабна мащабна грешка е неуспешна? - регекс, скала

Имам следното просто приложение:

object TestPatternMatch extends App {

if (args.length != 1)
throw new IllegalArgumentException("takes one argument which is a regex string that will be used to limit the org deletion")

val pattern = args(0).r
println("looking for orgs with name matching regex: " + pattern)

val orgs = Seq("zephyr-test-123", "abcdef", "zephyr-test-xyz-xyz-xyz")

orgs.foreach {
_ match {
case pattern(x) ⇒ println("matched " + x)
case y          ⇒ println("failed to match " + y)
}
}
}

Когато го наричам по-долу, очаквах да се класира на 1-во и 3-то място. Какво съм пропуснал?

[info] Running TestPatternMatch zephyr-test-.*
looking for orgs with name matching regex: zephyr-test-.*
failed to match zephyr-test-123
failed to match abcdef
failed to match zephyr-test-xyz-xyz-xyz

Отговори:

8 за отговор № 1

Моделът ви не съдържа () за да съответства на група x.

val R0 = "zephyr-test-.*".r
val R0() = "zephyr-test-123"    // matches, with no assignments
val R0(x) = "zephyr-test-123"   // MatchError, nothing to bind `x` to

val R1 = "zephyr-test-(.*)".r
val R1(x) = "zephyr-test-123"   // matches, x = "123"