PDA

View Full Version : Regular Expression to match Parenthesis ( {} ), Brackets ( (),[] )



parulkalra
25th November 2013, 12:42
Please someone provide me code for matching parenthesis and Brackets using regular expressions.

stampede
25th November 2013, 12:59
Is this some kind of school assignment ? There is another thread about this here : link (http://www.qtcentre.org/threads/57020-Define-a-QRegExp).

parulkalra
26th November 2013, 06:15
I had tried these codes but they are not working..

functionFormat1.setFontItalic(false);
functionFormat1.setForeground(Qt::green);
rule.pattern = QRegExp("[([^\]]+)]");
rule.format = functionFormat1;
highlightingRules.append(rule);

functionFormat1.setFontItalic(false);
functionFormat1.setForeground(Qt::green);
rule.pattern = QRegExp("\\b{([^}]+)}");
rule.format = functionFormat1;
highlightingRules.append(rule);

functionFormat1.setFontItalic(false);
functionFormat1.setForeground(Qt::green);
rule.pattern = QRegExp("\\b{[^}]*}");
rule.pattern = QRegExp("\\(([^)]+)\)");
rule.format = functionFormat1;
highlightingRules.append(rule);

and i tried this one also for parenthesis , but this again not working :

rule.pattern = QRegExp("\\b{[^}]*}");