Reputation: 3472
I'm using c++ with a header file that is quite large and would like to do a search for functions with specific return types, such as int. The problem lies in the fact that there is white space in front of the return types as shown below.
Set<Animal*> _animals;
int _getMonkeyCount(Zoo* zoo);
bool _addUnicorn(Animal* unicorn, int age = EXTINCT );
string _toString(Zoo* z);
void _addMonkeyz(Animal* monkey, List<string> fleaNames);
I would like to have a regex that matches one of the return types. For example bool, but I do not want to match the space in front of it.
Upvotes: 1
Views: 382
Reputation: 636
Not sure if this is exactly what you're looking for, but this might help someone else (matches function definitions, probably can be improved).
This Perl regex supports:
/((?:static\s+)?(?:const\s+)?(?:\w+\s+)(?:\*\s+)?(?:const(:?\s*))?)([\w|~]+)(\(.*\))(.*)\{/
Issues:
Upvotes: 0
Reputation:
'^ *int '
Remove the quotes when you run it. Of course, this highlights a few extra characters too...
Upvotes: 0
Reputation: 40927
You probably want something like:
/^\s\+\zsbool
The key here is \zs
which defines the start of the match. There is also \ze
to define the end of the match but you don't need that here.
Upvotes: 3