Bryan Dunphy
Bryan Dunphy

Reputation: 851

Need regex to locate c++ namespace declarations with unknown names

I'm trying to understand open source c++ code and I need a way to create a list of all the declared namespaces. I'm writing my code in Xojo (realbasic) with has built-in regex handling.

My problem is I'm not familiar enough with regular expressions to construct the correct expression to locate "namespace " followed by an unknown name then " {" all on the same line of text.

I can code everything else myself, I just need the proper regular expression. All help appreciated.

Upvotes: 1

Views: 453

Answers (1)

Qwertiy
Qwertiy

Reputation: 21410

You may try namespace\s+(\w+)\s*\{ for the most common cases without comments between words and won't match something like using namespace std;. Anyway namespaces can be nested, but here you'll get only flat list of all names.

Upvotes: 1

Related Questions