如何匹配除一组连续字符之外的任何字符?

时间:2014-04-22 03:16:00

标签: regex perl

我正在尝试匹配字符所有字符,直到模式A0343443(A[0-9]+

输入:

A546454 : This and that happened at C:\User\John\Documents\folder. There was an error reading 
the file
B546454 : This and that happened at C:\User\John\Documents\folder. There was an error reading the file
A595949: This other thing happened at C:\User\John\Documents\....

期望的输出:

A546454 : This and that happened at C:\User\John\Documents\folder. There was an error reading the file
A595949: This other thing happened at C:\User\John\Documents\....

由于行结尾不确定,我希望在到达A[0-9]+B[0-9]+时结束 我尝试了积极的前瞻:

^(?=A[0-9]+)

但是在首个A

时失败了

即。 Alot of chocolate导致它停止。

有什么想法吗?

谢谢

1 个答案:

答案 0 :(得分:1)

由于您的行以AB开头,因此您可以使用否定前瞻

^(?!B[0-9]+).+$

请参阅Live Demo