0

I'm trying to match extension-less url with or without query parameter. So far .+\/[^.\/]*$ matches some of them but it fails when . is present in query parameters

For example what i want is

http://www.example.com/ -> MATCH
http://www.example.com/abc -> MATCH
http://www.example.com/abc/def/ -> MATCH
http://www.example.com/abc/def.ext/ -> MATCH
http://www.example.com/abc?param=abc.def -> MATCH
http://www.anything.com/abc/def.ext/?param=abc.ext -> MATCH

http://www.example.com/abc.ext -> DONT MATCH
http://www.example.com/abc/def.ext -> DONT MATCH
http://www.anything.com/abc/def.ext?param=abc -> DONT MATCH
http://www.anything.com/abc/def.ext?param=abc.def -> DONT MATCH

The answers provided in How to match only extensionless URLs? fails when . or / are present in query parameters key or value. I've tried with many patterns but couldn't get desired result.

I am noob in regex. Please help.

Dr. DS
  • 644
  • 1
  • 7
  • 25
  • What language/tool are you using? What have you tried? What didn't work? What did you get? What did you expect? – Toto Nov 15 '18 at 17:12
  • @Toto, In my case i was trying in js. are not regular expressions are common to most of the languages, e.g. js, java, php.? – Dr. DS Nov 15 '18 at 17:39
  • No, they are not. See: https://stackoverflow.com/q/22937618/372239 and https://www.regular-expressions.info/tools.html – Toto Nov 15 '18 at 17:43
  • Few of my expressions was .+\/[^.\/]*$, .+\/[^.\/]*\?.*$, .+\/[^.\/]*(|\?.*)$, .+\/[^.\/]*(|\?.*[^.]*)$ – Dr. DS Nov 15 '18 at 17:44
  • @Toto Same is written on the stackoverflow link you shared *.. these languages share the same syntax.* – Dr. DS Nov 15 '18 at 17:46

1 Answers1

0

Try Regex: .+\/[^.\/]*?(?:\?.+)?$

Demo

Matt.G
  • 3,363
  • 2
  • 7
  • 21