help on regular expressions

Discussion Forums discussion help on regular expressions

This topic contains 0 voices and has 2 replies.

Viewing 3 posts - 1 through 3 (of 3 total)
Author Posts
Author Posts
July 4, 2008 at 1:41 am #439

webmailusr-msn
Member

Hi:

I need to customize some regex for output capture, I’d like to ask your help:

PHP:

Parse error: syntax error, unexpected T_STRING in Test.php on line 11

(No idea)

GCC:

Test.cpp:21: syntax error before `(‘ token

%f:%l:(%c:)?.* works for that but not when column is included:

Test.cpp:7:17: Mat.h: No such file or directory

July 8, 2008 at 6:29 pm #15998

simon
Key Master

PHP:

Try this:

.*in %f on line %l

GCC:

PN actually has built-in support for GCC error parsing, but this is currently broken in 2.0.9 as I need to change the regexes for the new engine.

To use .9 currently, it’s easy enough to fix the regex. The one you reference above expands to this:

(?P<f>.+):(?P<l>[0-9]+):((?P<c>[0-9]+):)? .*

Note that the following expansions are done:

%f = (?P<f>.+)
%l = (?P<l>[0-9]+)
%c = (?P<c>[0-9]+)

Regular expressions are by default “greedy” which means they’ll take as many characters for each match as they can. Because the last match bit is optional, the first reference to [0-9]+: ends up using the last number and colon (so the line number field matches the column in the string). The filename then includes the line number.

Results from your example:

File: Test.cpp:7

Line: 17

Col:

If we make the filename match bit “non-greedy” then it will take as little of the string as it can. With Xpressive (the new regular expressions engine) we do this by adding a question mark to the filename bit:

(?P<f>.+?):(?P<l>[0-9]+):((?P<c>[0-9]+):)? .*

The results are now:

File: Test.cpp

Line: 7

Col: 17

July 10, 2008 at 1:53 am #15999

webmailusr-msn
Member

Yeah, the second one did work (for gcc), however for php:

Parse error: syntax error, unexpected T_STRING in Test.php on line 11

.*in %f on line %l

does work in the test area, but not in the output window (weird, isn’t it?)

anyway thanks for the gcc trick!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.