我有一个文件包含很多行。
例如:
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:/
我想要的只是匹配以下几行:
HomeFolder=file:/user/local/home/
HomeFolder=file:/user/local/
HomeFolder=file:/user/
HomeFolder=file:/
请帮我提出能够达到上述情况的正则表达式。
答案 0 :(得分:1)
This regex将只捕获您想要的路径,并使用negative lookahead
仅捕获home/
之后是否还有子目录
^(HomeFolder=file:\/(?:user\/(?:local\/(?:home\/)?)?)?)(?!\w+\/)