Skip to content

Regex.unapplySeq should use m.find(0) instead of m.matches #5045

Closed
@scabug

Description

@scabug

In Regex the unapplySeq method uses m.matches to determine if the regex should extract matching groups. This should instead use m.find(0).

Using m.matches acts as if the pattern were implicitly anchored. Consider

val Re = """(x)""".r
val Re(x) = "xyz"
val Re(y) = "x"

When using a regular expression a user can state explicitly that they want anchoring and the Regex library should not mandate that decision. As an aside this often leads to people surrounding their patterns with ".PTRN." which can turn a nice fast pattern into one with heavy backtracking. See Mastering Regular Expressions by Friedl for details.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions