Give an example file with the content:

// find me
val ignore me = "" // I should not be found
  // find me
    // find me

I want to find all the lines with find me using ag silversearcher.

Basically, it should match any line optionally starting with any white space and a double space //.

I know that:

ag ^// example

only yields in the first line without spaces.

For the beginning of the line I know I can use ^, for whitespace it should be \s, and my custom string should either be // or it may need to be to escaped to: \/\/

That's why I thought:

ag ^\s*// example
ag ^\s*\/\/ example

Should do the trick, yet it finds also only the first line.

How can I match all the lines starting with white space and my custom string?

  • 4
    You forgot to enclose your regex in single quotes... ag '^\s*//' works fine here – don_crissti Nov 30 '18 at 16:19
  • @don_crissti Please add your comment as an answer for me to upvote and accept. – k0pernikus Dec 10 '18 at 14:40
  • I'll pass and here's why: as far as I am concerned this falls in the category of "user forgot some detail" or "improper syntax"... You can always add an answer if you feel like it. – don_crissti Dec 10 '18 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.