const regex = /^\s*(?:template\s*<\w+>\s+)?(?:(const|mutable|static|friend|unsigned)\s+)*\w+(::\w+)?(<([\w<> *&,()]|::)+>)?(,?\s+\*?\w+( = (-?\d+(\.\d+)?|((QMap|QList)<[^()]+>\(\))|(\w+::)*\w+(\([^()]+\))?)|\[\d+\])?)+;/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^\\s*(?:template\\s*<\\w+>\\s+)?(?:(const|mutable|static|friend|unsigned)\\s+)*\\w+(::\\w+)?(<([\\w<> *&,()]|::)+>)?(,?\\s+\\*?\\w+( = (-?\\d+(\\.\\d+)?|((QMap|QList)<[^()]+>\\(\\))|(\\w+::)*\\w+(\\([^()]+\\))?)|\\[\\d+\\])?)+;', 'gm')
const str = ` FilterType mFilter = FilterNone;
QgsRectangle mFilterRect;
QgsFeatureId mFilterFid = -1;
QgsFeatureIds mFilterFids;
std::unique_ptr< QgsExpression > mFilterExpression;
QgsExpressionContext mExpressionContext;
Flags mFlags;
QgsAttributeList mAttrs;
QgsSimplifyMethod mSimplifyMethod;
long mLimit = -1;
OrderBy mOrderBy;
InvalidGeometryCheck mInvalidGeometryFilter = GeometryNoCheck;
std::function< void( const QgsFeature & ) > mInvalidGeometryCallback;
static QHash<QString, Help> sFunctionHelpTexts;
friend class QgsOgcUtils;
template<typename> friend class QgsAbstractFeatureIteratorFromSource;
const QgsAbstractGeometry *mGeometry = 0;
mutable unsigned char *mP;
QgsPoint mEdgePoints[2];
double xxxx, yyyyy;
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;
QMap<QTreeWidgetItem *, QPair<QBrush, QBrush>> mTreeInitialStyle = QMap<QTreeWidgetItem *, QPair<QBrush, QBrush>>();
QMap<QTreeWidgetItem *, bool> mTreeInitialExpand = QMap<QTreeWidgetItem *, bool>();
QList<x> myList = QList<x>();
SHOULD NOT MATCH
virtual bool filterAcceptsRow( int row, const QModelIndex &source_parent ) const;`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions