Gerald
Gerald

Reputation: 31

What is the proper regular expression to cover multiple subdirectories?

I'm configuring a job on jenkins to exlude files on a github pushes. I want to exclude all pom.xml files, wherever the pom.xml would be located at (i.e. in the parent directory or any of the sub-directories.

Currently, this works:

(P|p)roject/[^/]+/pom.xml
(P|p)roject/[^/]+/[^/]+/pom.xml
(P|p)roject/[^/]+/[^/]+/[^/]+/pom.xml
(P|p)roject/[^/]+/[^/]+/[^/]+/[^/]+/pom.xml

this also works, however this one-liner is messy:

(P|p)roject/([^/]+|[^/]+/[^/]+|[^/]+/[^/]+/[^/]+|[^/]+/[^/]+/[^/]+/[^/]+)/pom.xml

My question: Is there a cleaner one-liner regex that would cover the parent directory and its sub-directories?

Upvotes: 1

Views: 227

Answers (2)

user557597
user557597

Reputation:

This might work

 # (?i)project/(?:[^/]*/)*pom\.xml

 (?i)
 project/
 (?: [^/]* / )*
 pom \. xml

Upvotes: 1

user3754372
user3754372

Reputation: 187

does following work?

(P|p)roject\/([^/]+\/)+pom\.xml

also note that you had not escaped forward slash and a dot character (.) which you should have

Upvotes: 2

Related Questions