0

When C++ source is compiled the errors are shown in this format
cPlusPlusSource.cpp:row_number:column_number: error: Error description text

What should the regular expression for this be ?

Please help!

3
Contributors
9
Replies
10
Views
4 Years
Discussion Span
Last Post by apanimesh061
0

I wish to extract the source name, row_number, column_number, error and error description text ..... !

1

Probably be best to just explode() using ':' to get an array of values. But I suppose you need to find it first right?

0

I'm no regicist, but I'll have a go -

preg_match("/(.+\.cpp):(.+):(.+):(.+):(.+)/",$str,$match);
array_shift($match);
print_r(array_map("trim",$match));

Works for me with the format given. Doubtless there's a nicer way.

Edited by diafol

0
There were some compilation errors! Terminating program execution...
The errors are as follows:
20121203.cpp: In function 'int main()':
20121203.cpp:3:2: error: 'inti' was not declared in this scope
20121203.cpp:6:1: error: expected ';' before '}' token

This is the error text that comes up. Actually I have made an Online IDE for c++ in php. I redirected the output of the console to the web page as text using pipelines/proc_open. I need to extract all the errors seperataly

0
preg_match("/(.+\.cpp):[0-9]:[0-9]:(.+):(.+)/",$str,$match);
array_shift($match);
print_r(array_map("trim",$match));

This would also work .... !

0

When I apply this regex to the text mentioned above :
I get this as output
Array ( [0] => 20121203.cpp:3:2: error: 'inti' was not declared in this scope [1] => 20121203.cpp [2] => error [3] => 'inti' was not declared in this scope )

But how to get the output with 20121203.cpp:3:2: error: 'inti' was not declared in this scope and 20121203.cpp:6:1: error: expected ';' before '}' token separately ??

0

preg_match_all("/(.+\.cpp):[0-9]*:[0-9]*:(.+):(.+)/",$str,$match);

This would be a better option to be used!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.