gordon, your version fails here if there is no column:
c:\tmp\test.cpp:1: error: message
does this work in your jre? i am using sun's 1.4.2_06 under win2k.
Sorry, I missed the part about the column being optional.
Try this one:
(.+?)
[0-9]+)
?
[0-9]+)
? (error|warning): (.+)
The first group needs a reluctant quantifier, otherwise it consumes
too much of the input when the column is optional and both line and
column numbers are provided.
The optional column uses two nested groups. Of these, the inner group
is the interesting one, since it contains (just) the column number,
whereas the outer group also contains the termating colon. The extra
?: after the outer group's opening parenthesis isn't strictly
necessary, but it's there to prevent the outer group from being
captured.
Here's my test again:
using regexp "(.+?)
[0-9]+)
?
[0-9]+)
? (error|warning): (.+)"
test 0: 'file.c:2:3: warning: foo':
1 (file): file.c
2 (line): 2
3 (col): 3
4 (type): warning
5 (msg): foo
test 1: 'file.c:2: warning: bar':
1 (file): file.c
2 (line): 2
3 (col): null
4 (type): warning
5 (msg): bar
test 2: 'file name.c:2: warning: gurka':
1 (file): file name.c
2 (line): 2
3 (col): null
4 (type): warning
5 (msg): gurka
test 3: 'file name.c:2:3: warning: baz':
1 (file): file name.c
2 (line): 2
3 (col): 3
4 (type): warning
5 (msg): baz
test 4: 'file n:ame.c:2: warning: gurka':
1 (file): file n:ame.c
2 (line): 2
3 (col): null
4 (type): warning
5 (msg): gurka
test 5: 'file n:ame.c:2:3: warning: baz':
1 (file): file n:ame.c
2 (line): 2
3 (col): 3
4 (type): warning
5 (msg): baz
test 6: 'file n:ame.c:4:5:6:2:3: warning: baz':
1 (file): file n:ame.c:4:5:6
2 (line): 2
3 (col): 3
4 (type): warning
5 (msg): baz
/gordon