Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multi_line builder option #98

Open
tgross35 opened this issue Jul 14, 2022 · 3 comments
Open

Add support for multi_line builder option #98

tgross35 opened this issue Jul 14, 2022 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@tgross35
Copy link

tgross35 commented Jul 14, 2022

regex has support for RegexBuilder::multi_line() (source here), would it be possible to add that here?

I think the implementation can be done with a simple transformation if full PCRE is enabled - ^ to (?<=^|\r\n|\n|\x0b|\f|\r|\x85) and $ to (?=$|\r\n|\n|\x0b|\f|\r|\x85)

@robinst
Copy link
Contributor

robinst commented Jan 12, 2023

Hey! You can already get that behavior by starting your regex with (?m). A multi_line method would be convenient to match regex's API though. I've added a "help wanted" label to this issue if anyone wants to contribute that work.

@robinst robinst added enhancement New feature or request help wanted Extra attention is needed labels Jan 12, 2023
@ash0080
Copy link

ash0080 commented Aug 31, 2023

Interesting, ?m seems not work, it will stop before the first line break even if I only use r".*"

let text = "hello\nworld";
let re = Regex::new(r"(?m)(.*)").unwrap();
let caps = re.captures(text).unwrap().unwrap();
dbg!(&caps);
dbg!(&caps.get(0).unwrap().as_str());

@robinst
Copy link
Contributor

robinst commented Sep 16, 2023

Ah, sounds like you want dot_matches_new_line which is (?s):

$ cargo run --example toy run '(?s)(.*)' 'hello\nworld'
captures: 0:[0..12] "hello\nworld" 1:[0..12] "hello\nworld"

@robinst robinst closed this as completed Sep 16, 2023
@robinst robinst reopened this Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants