Nayana Adassuriya
Nayana Adassuriya

Reputation: 24766

php search folders with specific pattern in the name

Environment: Windows 7 + XAMPP for Windows 5.6.15

I need to search a folder for sub-folders that match one of the pattern from these two

So these are the set of sub-folders I need to select

E0234.mysoftware.swl.px64
E0235.mysoftware.swl.px64
E0236.mysoftware.swl.px64
E0236.r2.mysoftware.swl.px64
E0237.mysoftware.swl.px64
E0237.r2.mysoftware.swl.px64
E0237.r3.mysoftware.swl.px64

These shouldn't select

E0237.A.mysoftware.swl.px64
E0237.b3.mysoftware.swl.px64

My question is can I do this search by using only one pattern?

Upvotes: 1

Views: 58

Answers (2)

user2705585
user2705585

Reputation:

What you are trying to do is make the .r* part optional which I have done using the following regex.

Regex: E\d*(\.r\d*)?\.mysoftware\.swl\.px64$

Flags used:

  • g for global search.

  • m for multi-line search.

Explanation:

  • (\.r\d*)? this makes the .r* part optional, thus facilitating searches of both patterns in one regex.

Regex101 Demo

Upvotes: 3

Tim007
Tim007

Reputation: 2557

Try this

(E[\w]+.mysoftware.swl.px64)|(E[\w]+.r[\w]+.mysoftware.swl.px64)

https://regex101.com/r/qG4iT4/1

Hope this helps.

Upvotes: 1

Related Questions