E0058

E0058#

Warning name: unused_non_capturing

Unnecessary non-capturing group in regex.

This warning is emitted when a regex contains a non-capturing group that is not needed. Consider simplifying the regex by removing the redundant group.

Erroneous example#

///|
test {
  let text = "xxabcyy"
  lexmatch text {
    (before, "a" "(?:b)" "c", after) => {
      inspect(before, content="xx")
      inspect(after, content="yy")
    }
    _ => fail("")
  }
}

Suggestion#

Remove the redundant non-capturing group:

///|
test {
  let text = "xxabcyy"
  lexmatch text {
    (before, "a" "b" "c", after) => {
      inspect(before, content="xx")
      inspect(after, content="yy")
    }
    _ => fail("")
  }
}