Tuesday 15 June 2010

Regex for finding substrings using Grep Console in Eclipse -


I'm using the Grep console in Eclipse to highlight the rows in the console output, for example. Depending on a regex, cancellation characters may have a precedent and / or a symbol after it, they can be surrounded by spaces, or substrings. In other words, I want to match the following lines (regardless of matter):

  Flight was canceled. [Canceled] Flight 101 are they going to cancel it?   

What is the regex to use to highlight these lines?

As ADDCJurer has already been explained, you should essentially match "cancel" For a case insensitive regular expression is required.

If you already have the output in the console, then the easiest way to create this expression is to select the word "cancel" in the output only, then click OK and add "Add expression" from the context menu. Select. A submenu will select a group that will add new expression, or create a new one. Expression items will be created using the following expression:

  (\ Qcancel \ E)   

Be sure to uncheck the "Case sensitive" checkbox, which Display is enabled by default for reasons and can prevent expression from matching your second line with capital 'C'.

This is basically the same expression ADDCU is provided, with some difference:

. * Matters are not included on the beginning and closing of the expression, as they are not necessary. Expression is also wrapped in brackets to create a capture group, allowing not only the string cancel for the whole line, but also to give that string a style. If you do not want to style that string, then you can leave the parentheses.

\ Q and \ E are always included in the expression to select the selected text string to ensure that any character with the selected string Expressions are not interpreted as characters.

This means that in your case, simple enough expression is simply:

 In this case, this is not necessary, because only words in  cancellation  There are characters.  

As suggested by ADDCair, cancellation

this expression also uses it as "quick expression", although for this There is no real need. The idea behind quick expression is that too long lines in the console can slow down pattern matching. The Grep console therefore will match how many characters in the configuration expression each row, this is a configurable limit. In the long line, any letter after this limit is ignored, which means that the rows which can not be identified only after the boundary and therefore are not styled.

If you configure a quick expression, then each row matches the first, with this expression, and only if the match is positive "normal" expression will be used in this situation, expression The entire line corresponds to The quick expression should therefore be as simple as possible, so that do not slow down the matching.

In your case, the expression is empty by using cancel as a quick expression and leaving the normal because the expression for the first time expresses positively with your line Eats, and then the blank expression also matches. If you have very long lines, then you can spend some expense, because the quick expression will ignore the length mentioned above. Also, accelerated expressions do not use the capture group, so you can not highlight the cancel string with a different style in this case.

No comments:

Post a Comment