Skip to content

Get position of first non-matching character #941

Closed as not planned
Closed as not planned
@casey

Description

@casey

I have a project with a bunch of integration tests which make a requests to a HTTP server we're writing, and then assert that the response matches a regex.

In case of a match, the test continues. In case of a mismatch, the test fails with an error message. The error messages print the regex and then the text, and it's often quite hard to figure out where in the text the regex wasn't able to match.

If we could get the index of the first non-maching character, or the index of the last matching character, then we could point out that position in the response body, which would improve our error messages a great deal.

Would it be possible to provide something like this?

impl Regex {
   fn first_mismatch_position(&self, str: &str) -> Option<usize> {
    todo!()
   }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions