3

How do I find a path and file name in a block of text?

Before you mark this as duplicate I know questions about file paths exist

For example

In file included from /some/directoy/3.33A.37.2/something else/dogs.txt,
                 from /some/directoy/something else/dogs.txt,
                 from /some/directoyr/3.33A.37.2/something else/dogs.txt,
                 from /var/log/xyz/10032008.log,
                 from /var/log/xyz/test.c:29:
Solution:
please the file something.h has to be alone without others include, it has to be present in release letter, 
in order to be included in /var/log/xyz/test.c and /var/log/xyz/test.h automatically
Other Note: 
The file something.c must contain the somethinge.h and not the ecpfmbsd.h because it doesn't contain C operative code.. everything good.. 

The following are the ideal matches:

/some/directoy/3.33A.37.2/something else/dogs.txt
/some/directoy/something else/dogs.txt
/some/directoyr/3.33A.37.2/something else/dogs.txt
/var/log/xyz/10032008.log
/var/log/xyz/test.c:29 (this is a tricky one, ok with out it)
/var/log/xyz/test.c
/var/log/xyz/test.h

Going further what if I find an answer how can I change it to work with \ instead of / directories

Community
  • 1
  • 1
Whitecat
  • 3,882
  • 7
  • 48
  • 78

2 Answers2

4

You can use a regex like this:

\/.*\.[\w:]+

Working demo

enter image description here

Btw, if you want to allow backslashes in the path you can have:

[\\\/].*\.[\w:]+
Federico Piazza
  • 30,085
  • 15
  • 87
  • 123
2

This looks to be working:

\/[^,:]*\.\w+

See demo.

You can fine-tune this if you know the exact extensions, their lengths and what characters they have. As for me, \w+ would do to match extensions.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Nice I like this one. It does both `\ /`. I am parsing "big data" I don't know any extension. I am hoping to make this as general as possible. – Whitecat Mar 18 '15 at 22:05