hello, I want to select all first 10 lines from severel documents. I made this regex, but is not very good. Maybe someone give me a little help:
\A^.*(?:\R.*){10}
hello, I want to select all first 10 lines from severel documents. I made this regex, but is not very good. Maybe someone give me a little help:
\A^.*(?:\R.*){10}
I didn’t try it in a project search, just the current file search. Give me a second.
38 matches across 38 files
Don’t know what to say, but it works for me. I’d double check your search toggles and make sure regex is enabled etc. It works perfectly for me. Again, I hope you aren’t including the dot at the end. Everytime you post my example, you include the dot. it should be:
(\A(?:.*\n){10})
Why are you using the “whole word” option?
(and no need for the “(?:” stuff, “\A(.*\n){10}” should do just fine.)
I must have copied my pattern wrong the first time. \A(?:.*\n){10}
worked for me as well, so no capturing group needed.
@mlf, I see the comment wasn’t meant for me now. Sorry for the confusion. I was the one who supplied the regex, so I thought you were speaking to me.
I mistook \R
for recursion ?R
(not every regular expression engine has this \R
).
But now I better understand what is being attempted.
Anyways, \A^.*(?:\R.*){10}
can potentially grab 11 lines in the right scenario which wold not fit your description, so probably not best. \A(?:.*\R){10}
Would grab a hard 10 lines. If you don’t want to count empty lines, then \A(?:.*\R*){10}
would grab 10 lines with actual text.
So depending on what you are actually looking for either: \A(?:.*\R){10}
or \A(?:.*\R*){10}
would probably be best.
If a file does not have 10 lines, but you still want to grab up to the most you can, then the either of the following may be better: \A(?:.*\R){0,10}
or \A(?:.*\R*){0,10}
.