问题
I want clang-format to not modify comment lines I use to separate functions from each other. I think commentPragmas is the right option for that, but I can't find info on the clang-format regex format.
I tried commentPragmas: '^/\*-.*' to capture my separator lines that look like this
/*------------------------------------------------------------------*/
But the above regex did not work... Where can I look up the syntax for regexes for clang-format?
回答1:
TL/DR: The flavor is POSIX ERE
As far as I can tell, the regex flavor isn't documented in ClangFormat docs, that's pretty unhelpful.
Let's dig into the source code to find out.
There's a class named ContinuationIndenter, which has a CommentPragmasRegex field, of type... llvm::Regex right here. Well, that's not really helpful either but maybe it's just a wrapper...
Turns out llvm::Regex is a wrapper around... llvm_regex. The header includes this comment though:
This file implements a POSIX regular expression matcher. Both Basic and Extended POSIX regular expressions (ERE) are supported. EREs were extended to support backreferences in matches. This implementation also supports matching strings with embedded NUL chars.
In the header that defines llvm_regex we can also find this comment:
This code is derived from OpenBSD's libc/regex
来源:https://stackoverflow.com/questions/39986368/clang-format-regex-syntax-reference