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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -