Reputation: 143
At work, I have a requirement to create a perl-style regular expression for C comments (/*) for comments left in our code. Our business analysts had new requirements, and these were all prefaced with "BA", and I'm supposed to somehow scan the comments to find these instances. I am very unfamiliar with regular expressions and after reading more about them, I'm lost as to how to target comment blocks with only the BA string.
Any guidance would be greatly appreciated.
Upvotes: 2
Views: 1024
Reputation: 30690
I'm not aware of any weird escaping rules for C comments, so I think you just want something like this:
/\/\*.*?\/\*/s
The s
flag means that the .
will also match carriage returns, so the comments can cross multiple lines.
To match only comments starting with "BA", you'd want:
/\/\*BA.*?\/\*/s
Consider adding the i
flag if the "BA" part can be lowercase.
Upvotes: 3
Reputation: 50991
find . -regex ".*\.[ch]" | xargs grep -regex "/\* *BA"
What that does:
Upvotes: 0