How to get regex submatches? (using --json
)
#2814
-
Hello! I have a number of files with lines like Repro: $ cd `mktemp -d`
$ echo 'type: foo, bar' > file1
$ echo 'type: baz' > file2
$ rg --json '^type: (.*)' | rg '"type":"match"'
2:{"type":"match","data":{"path":{"text":"file2"},"lines":{"text":"type: baz\n"},"line_number":1,"absolute_offset":0,"submatches":[{"match":{"text":"type: baz"},"start":0,"end":9}]}}
5:{"type":"match","data":{"path":{"text":"file1"},"lines":{"text":"type: foo, bar\n"},"line_number":1,"absolute_offset":0,"submatches":[{"match":{"text":"type: foo, bar"},"start":0,"end":14}]}} We can see the submatches: [{"match":{"text":"type: baz"},"start":0,"end":9}] [{"match":{"text":"type: foo, bar"},"start":0,"end":14}] But I'd expect to get (for each):
I also tried with |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Could you please provide a full reproduction? Give me a command that I can run as-is. You've described your input, but you need to show your input. It's okay to make something up that models your real data, just so long as it exhibits the same problem. |
Beta Was this translation helpful? Give feedback.
-
OK, so the issue here is that
Otherwise, I think you're probably looking for #2325. The main issue is that adding capture groups will result in a perf hit. So it means that you have to opt into it. Which is kinda unfortunate. |
Beta Was this translation helpful? Give feedback.
-
hello mate .. iam new in github and i have no idea of how to use these files. I want to download some files in rapidgator but the time and speed restriction prevent me to do so |
Beta Was this translation helpful? Give feedback.
OK, so the issue here is that
submatches
is not the same as capture group matches.submatches
in this context refers to the list of matches within a line. For example:Otherwise, I think you're probably looking for #2325. The main issue is that adding capture groups will result in a perf hit. So it means that you have to opt into it. Which is kinda unfortunate.