bender86
3rd March 2011, 12:33
Hi.
I'm having some trouble using QRegExp to match a multiline expression. Actually I'm trying to write a Markdown syntax highlighter, and I'd like to recognize something like:
Heading 1
===========
Heading 2
-----------
I tried ".+\\n=+" and similar, with no success.
EDIT:
I made some attempts with the RegExp example, and I found out I should be able to use "[^\\n][\\w\\s][^\\n]+\\n=+".
The problem is that QSyntaxHighlighter::highlightBlock() is called once per line, so I can't match anything which spans more than one line. Documentation suggests using a state based highlighter, but I don't think it would work since I know if a line is an heading only when I read the next line.
Any idea how to do that (except using alternative syntax for headings off course)?
I'm having some trouble using QRegExp to match a multiline expression. Actually I'm trying to write a Markdown syntax highlighter, and I'd like to recognize something like:
Heading 1
===========
Heading 2
-----------
I tried ".+\\n=+" and similar, with no success.
EDIT:
I made some attempts with the RegExp example, and I found out I should be able to use "[^\\n][\\w\\s][^\\n]+\\n=+".
The problem is that QSyntaxHighlighter::highlightBlock() is called once per line, so I can't match anything which spans more than one line. Documentation suggests using a state based highlighter, but I don't think it would work since I know if a line is an heading only when I read the next line.
Any idea how to do that (except using alternative syntax for headings off course)?