How to write a grep that pick up specific word in the third line?

152 Views Asked by At

For example if I have a doc with these 3 lines. I know ^feat is matching the first feat and how can I match the third line reg? I tried ^reg does not seems work.

feat(ad): make new ad
some note here
reg(ad): need a walk through

It meant to be used within a .changelogrc file for https://github.com/rafinskipg/git-changelog

2

There are 2 best solutions below

4
On

You can try using the following regex:

^[^\r\n]*?\r\?\n[^\r\n]*?\r\?\nreg

This regex will "eat" two lines from the beginning, and then check if reg appears at the start of the third line. Note that I used the quantity \n|\r\n to represent a newline, to cover both Windows or Linux (you never mentioned your OS).

If you want to match any line which starts with reg then you can try:

^(?:[^\r\n]*?\r\?\n)*reg
2
On

Having a look at the sources of that tool, you should enable debug logging to see the git command that is issued which is logged with this.log('debug', 'Executing : ', git_log_command);. From a quick look at the sources I'd say you get something like git log --grep="^feat|^reg" which is not correct but should instead be git log --grep="^feat\|^reg". But anyway, if you have the log line, you can try to execute the command standalone to see whether it works for you and can play with it to find out why not if not.