在我的情況下,我想找到(使用Python正則表達式)所有行而不是包含單詞「錯誤」或「空」。在代碼:如何找到不包含特定單詞的所有行?
varformals:PAR_OPEN PAR_CLOSE {}
| PAR_OPEN varform PAR_CLOSE {}
/* error /|錯誤PAR_CLOSE {}
/錯誤/|錯誤變量PAR_CLOSE {}
/錯誤*/| PAR_OPEN錯誤PAR_CLOSE {}
;
在我的情況下,我想找到(使用Python正則表達式)所有行而不是包含單詞「錯誤」或「空」。在代碼:如何找到不包含特定單詞的所有行?
varformals:PAR_OPEN PAR_CLOSE {}
| PAR_OPEN varform PAR_CLOSE {}
/* error /|錯誤PAR_CLOSE {}
/錯誤/|錯誤變量PAR_CLOSE {}
/錯誤*/| PAR_OPEN錯誤PAR_CLOSE {}
;
描述
1st Capturing group (^((?!error|empty).)*$)
^assert position at start of a line
2nd Capturing group ((?!error|empty).)*
Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
Note: A repeated capturing group will only capture the last iteration.
Put a capturing group around the repeated group to capture all
iterations or use a non-capturing group instead if you're not interested
in the data
(?!error|empty) Negative Lookahead - Assert that it is impossible to match the regex below
1st Alternative: error
error matches the characters error literally (case sensitive)
2nd Alternative: empty
empty matches the characters empty literally (case sensitive)
. matches any character (except newline)
$ assert position at end of a line
g modifier: global. All matches (don't return on first match)
m modifier: multi-line. Causes^and $ to match the begin/end of each line (not only begin/end of string)
它必須與'正則表達式'? –
正則表達式的使用是有道理的,我敢肯定,這是一個重複,如果你認爲情況並非如此,就進行編輯。 –
其實「Python正則表達式」與正則表達式不同。 (pythex模擬器[pythex.org]) 另外我更喜歡一個「蟒蛇正則表達式」,但如果你有一個很好的選擇,請發佈。 :D – HackSlash