pyqt qsyntaxhighlighter编辑器中的python正则表达式

时间:2018-04-21 14:52:30

标签: python editor pyqt5 qregularexpression

我正在使用pyqt构建文本编辑器,我想设置字体STYLES [错误]时(“)不以另一个(”)结束,当它正确设置字体STYLES [string]时,我的问题是什么时候(“ “)结束...(”“之后的任何字符采用字体STYLES [错误]我想停止它但不能设置正确的正则表达式

`
STYLES = {
    'string'   : format('magenta') ,
    'error'    : format('red' , 'underline') ,
}
rules +=[(r'"[^"\\]*(\\.[^"\\]*)*', 0, STYLES['error']),
         (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']),]
`

1 个答案:

答案 0 :(得分:0)

试一试:

        ## error
        (r'"[^"\\]*(\\.[^"\\]*)*.', 0, STYLES['error']),
        (r"'[^'\\]*(\\.[^'\\]*)*.", 0, STYLES['error']),

        # Double-quoted string, possibly containing escape sequences
        (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']),
        # Single-quoted string, possibly containing escape sequences
        (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']),

enter image description here