Hi, sorry for being very newbie-ish on this subject.
I am tearing my hair out over regular expression syntax, and I am unable to create a regexp for jumping to any line. Since there are no examples that include the output they are supposed to match, and there are no error messages (only 'Cannot jump to item under cursor'), I am not getting anywhere.
The Line I want to match is fairly simple:
[checkstyle] C:\java\MyClass.java:73: 'if' construct must use '{}'s.
However, I have been unable to create a regexp that matches this.
I know I cannot expect you to do this for me, but example expressions, _along with the output they_ would be extremely helpful for me.
'Jump To' regexps
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
Murray
Re: 'Jump To' regexps
Magnus
Is the line your trying to match always the same as your example? If so, there is no reason to use regexp - just match it exactly.
ie.
highlight a line you want to match (or type it in directly in the search dialogue)
Search -> Find (or press F5)
Make sure the regexp box is ticked OFF.
find next.
Or have I misunderstood?
Murray
Is the line your trying to match always the same as your example? If so, there is no reason to use regexp - just match it exactly.
ie.
highlight a line you want to match (or type it in directly in the search dialogue)
Search -> Find (or press F5)
Make sure the regexp box is ticked OFF.
find next.
Or have I misunderstood?
Murray
-
Jens Hollmann
Re: 'Jump To' regexps
I think you want to jump to a line according to the output of a tool.
The regexp is not so complicated:
^\[checkstyle\] \(.*\):\([0-9]+\):
The file is the first group and the line the second. You have to set this in the tools-dialog.
^ matches the beginning of a line
\[checkstyle\] matches the literal text "[checkstyle]". You have to escape the "[" and "]" with "\"!
then a space
\(.*\) matches anything (except newline) and the "\(" and "\)" marks this as group 1. This should be your filename.
: matches a ":"
\([0-9]+\) matches one or more digits and the "\(" and "\)" marks this as group 2. This should be your line.
: finally matches another ":"
Mind that you have to close the output window and reinvoke your tool every time you change the settings! The regexp for jumping is stored in the output window on opening it, so changing the settings has no effect until you reopen the window by running the tool again!
I'm developing the jump-to-regexp like this:
Invoke the tool, so that you get some output with lines to jump to.
Then open the find-dialog and fumble around with some regexps until you match only the lines of the output that you want to jump to. This is easy because the find-dialog stays open all the time and you can change your regexp until it suffices and the matched string is highlighted so that you can see what is matched.
Then put "\(" and "\)" around the parts of the regexp that match file and line.
This is the regexp you're looking for.
HTH
Jens
The regexp is not so complicated:
^\[checkstyle\] \(.*\):\([0-9]+\):
The file is the first group and the line the second. You have to set this in the tools-dialog.
^ matches the beginning of a line
\[checkstyle\] matches the literal text "[checkstyle]". You have to escape the "[" and "]" with "\"!
then a space
\(.*\) matches anything (except newline) and the "\(" and "\)" marks this as group 1. This should be your filename.
: matches a ":"
\([0-9]+\) matches one or more digits and the "\(" and "\)" marks this as group 2. This should be your line.
: finally matches another ":"
Mind that you have to close the output window and reinvoke your tool every time you change the settings! The regexp for jumping is stored in the output window on opening it, so changing the settings has no effect until you reopen the window by running the tool again!
I'm developing the jump-to-regexp like this:
Invoke the tool, so that you get some output with lines to jump to.
Then open the find-dialog and fumble around with some regexps until you match only the lines of the output that you want to jump to. This is easy because the find-dialog stays open all the time and you can change your regexp until it suffices and the matched string is highlighted so that you can see what is matched.
Then put "\(" and "\)" around the parts of the regexp that match file and line.
This is the regexp you're looking for.
HTH
Jens
-
Magnus Torfason
Re: 'Jump To' regexps
Thank you, this works like a charm, and your directions are very concise and to the point, and I believe I understand how this works.
There is just one question, to enhance my understanding. Since the line includes three colons ':', how does the regexp now that the filename should go all the way to the second colon (after '...Class.java'), and not just to the first colon (after '[checkstyle] C').
[checkstyle] C:\java\MyClass.java:73:
Thanks again,
Magnus
There is just one question, to enhance my understanding. Since the line includes three colons ':', how does the regexp now that the filename should go all the way to the second colon (after '...Class.java'), and not just to the first colon (after '[checkstyle] C').
[checkstyle] C:\java\MyClass.java:73:
Thanks again,
Magnus
-
Stephan
Re: 'Jump To' regexps
It's because ".*" is greedy. This is .* 'eats' every single character (except new lines as Jens already said) that follows - unless it's force to give up some of the already consumed chararcters to allow the following part of the regex ":\([0-9]+\):" to match.
So, at first .* matches everything that's not already consumed by "^\[checkstyle\] ", then ":" (the one before the [0-9] part) forces a "fall back": .* gives up a char at the time and ":" tries to macht again. This goes back and forth until ":" can match. In this case that's immediytely: ":" can match the last char in the line (the ":" after 73 in the example line).
Now, the whole RegExp needs to match the \([0-9]+\) part and so .* needs to give up some more chars.
HTH
Stephan
So, at first .* matches everything that's not already consumed by "^\[checkstyle\] ", then ":" (the one before the [0-9] part) forces a "fall back": .* gives up a char at the time and ":" tries to macht again. This goes back and forth until ":" can match. In this case that's immediytely: ":" can match the last char in the line (the ":" after 73 in the example line).
Now, the whole RegExp needs to match the \([0-9]+\) part and so .* needs to give up some more chars.
HTH
Stephan