0

i am building text editor with pyqt and i want to set font STYLES[error] when (") not end with another (") , and when it end correctly set font STYLES[string] , my problem is when ("") ending ... any character after ("") takes font STYLES[error] and i want to stop it but can't set correct regular expression

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

1 回答 1

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

在此处输入图像描述

于 2018-04-21T18:45:35.863 回答