Comments (4)
Using a multiline regexp, when the regexp matches strings that come immediately one after another, it bungles the line numbers of all of them.
This is an incomplete description of the problem you're reporting. It isn't just when a regex matches strings that are adjacent, it's also required that you use the -r/--replace
flag to replace matches with something else. This can be easily demonstrated by omitting the -r/--replace
flag and observing that the line numbers are correct:
$ rg -nU '^:properties:\n:id: (.*)\n:end:' test.txt
1::properties:
2::id: fnord
3::end:
4::properties:
5::id: boccob
6::end:
7::properties:
8::id: d321fdddffff
9::end:
10::properties:
11::id: clowns
12::end:
Indeed though, the adjacency part of this seems important. If instead I use the following haystack as test2.txt
:
:properties:
:id: fnord
:end:
ZZZ
:properties:
:id: boccob
:end:
ZZZ
:properties:
:id: d321fdddffff
:end:
ZZZ
:properties:
:id: clowns
:end:
Then the line numbers change:
$ rg -nU '^:properties:\n:id: (.*)\n:end:' -r '$1' test2.txt
1:fnord
5:boccob
9:d321fdddffff
13:clowns
from ripgrep.
As you say, I forgot to mertion the --replace
. Changed the title.
from ripgrep.
I'm not proficient with Rust, but I could try to look for the problem. Any pointers on where to look?
from ripgrep.
Likely in grep-printer
. Look at the "standard" printer.
That's where I would start anyway.
from ripgrep.
Related Issues (20)
- Feature Request: Early Bail Out for Time-Consuming Regex Matches in pcre2 HOT 4
- [perf] rg does not use globs to prune recursion when it can HOT 4
- cursor disappearing HOT 1
- failing test: f2361_sort_nested_files
- The same `LineTerminator` is being used for searching and printing
- `--pre` doesn't work on Windows (CMD, MSYS2 bash, Powershell) HOT 16
- ARMv8 release binary for RPI 5 HOT 2
- ripgrep 14.1.0 exit silently when stdin is not connected (GNU parallel without --tty) HOT 8
- Feature Request: search for binary data by supplying a hex string HOT 9
- Is it possible to add a search for just a set of directories as a type? HOT 1
- Allow following symlinks to files HOT 2
- WalkDir ignores files that are in .gitignore outside of current git repository HOT 2
- Multiple quirks in ignore behavior HOT 1
- BUG: exit code on windows not stable (wrong on first run, then stable), seems to leak HOT 9
- pcre2 reset match \K drops submatches HOT 1
- ripgrep is slower than LTREP matching `[A-Z][A-Z]+` HOT 3
- --files is listing files that won't be searched into HOT 4
- ripgrep ignore files inside `.github` folder HOT 5
- Potentially incorrect or undocumented .gitignore files handling
- `--text` flag only works if it's late in the command HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ripgrep.