Reputation: 31
I have a file contains many lines.
For example:
HomeFolder=file:/user/local/home/joe/
HomeFolder=file:/user/local/home/max/
HomeFolder=file:/user/local/home/ted/
HomeFolder=file:/user/local/home/
HomeFolder=file:/user/local/
HomeFolder=file:/user/
HomeFolder=file:/
What I want is to match only the following lines:
HomeFolder=file:/user/local/home/
HomeFolder=file:/user/local/
HomeFolder=file:/user/
HomeFolder=file:/
Please help me come up with the regular expression that would achieve the above scenario.
Upvotes: 0
Views: 32
Reputation: 6360
This regex will capture only the paths you want, and uses a negative lookahead
to only capture if there aren't anymore subdirectories after home/
^(HomeFolder=file:\/(?:user\/(?:local\/(?:home\/)?)?)?)(?!\w+\/)
Upvotes: 1