2017-07-05 10:49 GMT+03:00 Christian Brabandt <cblists@256bit.org>:
>
> On Mi, 05 Jul 2017, Igor Forca wrote:
>
>> Hi,
>> I have a log file with several text OK and error messages.
>>
>> OK message is always: AAA000A
>>
>> Error message starts with AAA, then three numbers (but not three zeros) and letter A.
>> Error sample: AAA001A
>>
>> From the Vim Regular Expression web site:
>> http://vimregex.com/#metacharacters
>> I can see:
>> \d digit
>> \D non-digit
>>
>> To find OK and error message in vim:
>> /AAA\d\d\d\D
>
> This will find okay or error messages.
>
>> but how to get only error messages.
>>
>> Something like:
>> - use: /AAA\d\d\d\D
>> - except: /AAA000A
>
> Something like this should work:
> A\{3}\%(\([^0]\d\{2}\)\|\(\d[^0]\d\)\|\(\d\{2}[^0]\)\)A
> which matches 3 As, followed by either:
> - a non-zero followed by 2 digits followed by another A or
> - a digit followed by a non-zero followed by another digit and A or
> - 2 digits followed by a non-zero followed by another A
These are too much combinations. I would suggest using lookahead instead:
\vAAA%(.{,2}[1-9])@=\d{3}A
I.e. three A's followed by three digits and A where position just
after three A's is occupied by zero..two characters followed by 1-9.
You already have three branches for three-digit error code. Will have
four branches for four-digit, etc. With lookahead you always need only
one lookahead for any given number of digits.
There are also concats as an alternative to positive lookahead, but
since they are not in PCRE and do not present anything new I do not
use them.
>
>
> Best,
> Christian
> --
> Warum überquerte das Huhn die Straße?
> Kindergärtnerin:
> Um auf die andere Straßenseite zu kommen.
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment