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

Multiline mode cannot be enabled or disabled using inline modifiers #1262

Closed
dprobinson opened this issue Apr 21, 2019 · 2 comments
Closed

Comments

@dprobinson
Copy link

What version of ripgrep are you using?

ripgrep 11.0.1 (rev e7829c0)
-SIMD -AVX (compiled)
+SIMD -AVX (runtime)

How did you install ripgrep?

Compiled from source

What operating system are you using ripgrep on?

Arch Linux

Describe your question, feature request, or bug.

It's possible to turn case sensitivity (and presumably other modes) on and off using inline modifiers, but this doesn't extend to multiline mode "(?m)".

If this is a bug, what are the steps to reproduce the behavior?

Create the following corpus.txt:

testing
RIP
GREP
again

With PCRE2 engine:

rg -P "(?m)RIP\nGREP" corpus.txt

Output (blank - see bug #1261):

With Rust's engine:

rg "(?m)RIP\nGREP" corpus.txt

Output:

the literal '"\n"' is not allowed in a regex

Consider enabling multiline mode with the --multiline flag (or -U for short).
When multiline mode is enabled, new line characters can be matched.

N.B. It's not possible to disable multiline mode via inline modifiers either. Eg:

rg -U "(?-m)RIP\nGREP" corpus.txt

Output:

2:RIP
3:GREP

When you wouldn't expect a match.

If this is a bug, what is the actual behavior?

See above for output. Multiline mode cannot be enabled or disabled using inline modifiers.

If this is a bug, what is the expected behavior?

ripgrep to read the inline modifiers and enable or disable multiline mode for the relevant parts of the provided pattern as directed.

@BurntSushi
Copy link
Owner

ripgrep's multiline mode is not the same as regex multiline mode. The former just allows patterns to match over multiple lines. The latter just makes anchors match at line boundaries (which is enabled by default for all searches, regardless of whether ripgrep's multiline mode is enabled or not). They are entirely orthogonal options.

@dprobinson
Copy link
Author

That makes sense. I'd wondered if this was actually a bug or not, thanks for clarifying!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants