Skip to content

captures_iter and find_iter handle newline differently #850

Closed
@dpk2442

Description

@dpk2442

What version of regex are you using?

1.5.5

Describe the bug at a high level.

When running the same regex against the same input, captures_iter and find_iter yield different results.

What are the steps to reproduce the behavior?

let re = regex::Regex::new("(?m)^([^ ]+?)$").unwrap();
let text = "line1\nline2";

println!("captures_iter");
for cap in re.captures_iter(text) {
    println!("{:?}", cap.get(0).unwrap().as_str());
}

println!("\nfind_iter");
for mat in re.find_iter(text) {
    println!("{:?}", mat.as_str());
}

What is the actual behavior?

captures_iter
"line1"
"line2"

find_iter
"line1"
"\nline2"

What is the expected behavior?

I expected the output if the call to find_iter to be consistent with the output of captures_iter, but one includes the newline character and one does not.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions