regex - regexp: how to remove the beginning of the path -
i have regular expression parse gcc compilation output:
^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$ the first sub expression - ^(..[^:]*) mark file error occurs.
for example, input:
main.c:1156:13: error: invalid storage class it mark
main.c and input:
folder/main.c:1156:13: error: invalid storage class it mark
folder/main.c how can change first sub expression mark file name without full path?
i suggest replacing (..[^:]*) (?:[^\r\n:]*/)?([^:\r\n]*):
^(?:[^\r\n:]*/)?([^:\r\n]*):([0-9]+):?([0-9]+)?:? (.*)$  ^^^^^^^^^^^^^^^^^^^^^^^^^^ see regex demo
the change part matches:
- (?:[^\r\n:]*/)?- 1 or 0 occurrences of:- [^\r\n:]*- 0 or more chars other- :, cr , lf , then
- /-- /char
 
- ([^:\r\n]*)- group 1: 0 or more chars other- :, cr , lf
Comments
Post a Comment