1

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.

Bryan Dunphy
  • 799
  • 1
  • 10
  • 22
  • 1
    You'd be better off using something like Doxygen, C++ is notoriously hard to parse (your simple definition could miss a lot of stuff and pick up stuff you don't want). – Mat Dec 24 '18 at 16:50
  • If you know it's all on the same line: `namespace (.+)? \{` – mnistic Dec 24 '18 at 16:51
  • @Mat They make a Doxygen report available online. How would I get a namespace list from it? – Bryan Dunphy Dec 24 '18 at 18:35

1 Answers1

1

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.

Qwertiy
  • 19,681
  • 15
  • 61
  • 128