regular expression match

I am trying to match a similar line using grep with regular expression

the line is
/remote/mac/pbbbb/abc/def/hij/hop/include/abc/tif/element/test/testfiles/Office.cpp:57: const OfficeType& getType().get() const;

I just need to extract the bold characters using grep with regular expression.

I have been trying a couple of regex patterns, but dont seem to be getting it right.

Could you please help.

grep will grep for you the whole line where the pattern matches...

Try it with sed...

sed 's/\(.*\):.*/\1/'

Or awk...

awk -F: '{print $1}'

thanks for the answer

but the problem is i can have more than one lines continuously in the string.I just need to extract the whole filepath.

I was thinking of using grep -o in order to display just the matching pattern. Would this be possible ?

/remote/mac/pbbbb/abc/def/hij/hop/include/abc/tif/element/test/testfiles/Office.cpp:57: const OfficeType& getType().get() const;
/remote/mac/pbbbb/abc/def/hij/hop/include/abc/tif/element/test/testfiles/Office.cpp:57: const OfficeType& getType().get() const;

The above two commands will work for more than one line too.

if you have GNU grep,

grep -o '/remote/mac/pbbbb/abc/def/hij/hop/include/abc/tif/element/test/testfiles/Office.cpp' file

Indeed it works, Thanks for the reply.