4

I'm looking for a regex pattern that I need for IIS. Basically I want it to match any directory path but reject file paths. I've searched all over with little luck.

Example: Match: /directory/content/css/ Match: /directory/content/css Reject: /directory/content/css/main.css Reject: /directory/content/css/main.anything

!--Due to feedback I've made some changes (Apologies this is my first time on the forum)--!

So far I've put together this pattern: ^(\/.*)(.*)*[^.*]$ It appears to start out ok accepting anything starting with / but it still accepts extensions.

Thanks

jaco0646
  • 15,303
  • 7
  • 59
  • 83
user3006019
  • 55
  • 2
  • 6
  • 2
    Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: [Stack Overflow question checklist](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist) – HamZa Nov 18 '13 at 19:28
  • Would something like this work for you? http://msdn.microsoft.com/en-us/library/system.uri.iswellformeduristring.aspx – aust Nov 18 '13 at 19:32
  • what about directories with no trailing slash? `http://webroot/content/css` – OGHaza Nov 18 '13 at 19:35
  • or directories with dots.. with no trailing slash – the_lotus Nov 18 '13 at 19:39
  • ^ yup, that was what I was going to get at – OGHaza Nov 18 '13 at 19:39
  • What language do you use? You don't need regex for that. – matewka Nov 18 '13 at 19:42

2 Answers2

0

What about this \/.*?[\w:]+

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

although it can leave / at the end

-3

Regex:

(?:\..*(?!\/))+

This regex will match if you got a file path..

Regex101

Alex Tape
  • 2,291
  • 4
  • 26
  • 36