Skip to content

Null alternation causes infinite loop #558

Closed
@rctcwyvrn

Description

@rctcwyvrn

The first regex runs instantly as expected, but the second one appears to run forever. The first has @ in the alternation while the second has it outside as an anchor.

Running them on regex101 shows that their engines run the two regexes in a similar number of cycles and match the same results.

  func testInfiniteLoop() {
    print("Starting regex")
    // let regex = try! Regex(#"(?:\d|\w|\.|-|_|%|\+|@)+"#)
    let regex = try! Regex(#"(?:\d|\w|\.|-|_|%|\+|)+@(?:\d|\w|\.|-|_|%|\+|)+"#)
    print(try! regex.firstMatch(in: "[email protected]"))
    print("Finished regex")
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions