【问题标题】:python regular expression in pyqt qsyntaxhighlighter editorpyqt qsyntaxhighlighter 编辑器中的 python 正则表达式
【发布时间】:2018-04-21 14:52:29
【问题描述】:

我正在使用 pyqt 构建文本编辑器,我想在 (") 不以另一个 (") 结尾时设置字体 STYLES[error] ,并且当它正确结束时设置字体 STYLES[string] ,我的问题是当 (" ") 结束... ("") 之后的任何字符都采用字体 STYLES[error] 我想停止它但无法设置正确的正则表达式

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

【问题讨论】:

    标签: python editor pyqt5 qregularexpression


    【解决方案1】:

    试试看:

            ## 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']),
    

    【讨论】:

    • 谢谢它对我有用,你能帮我写 re that set font [error] if ";"没有写在行尾。
    猜你喜欢
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多