0

I want to extract all words between "products" and / (forward slash) or period (.)

In the example below, I want to extract "pants" and "shoes"

www.site.com/products/pants.html

www.site.com/products/shoes/sneakers.html

The closest I came was this (?<=/products/).*($.|/) How do I include "." OR "/"

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Gym Rat
  • 39
  • 6
  • 2
    One more thing: please add a tag for the language you are using, as different languages support different regex features. – Cary Swoveland Jul 02 '22 at 01:13

1 Answers1

2

If nth occurance is e.g. two:

^(?:[^\/]*\/){2}([^.\/]+)

See this demo at regex101

bobble bubble
  • 16,888
  • 3
  • 27
  • 46
  • 1
    You don't need to escape forward slashes - they have no special regex meaning. That some languages *delimit* regex use forward slashes is not relevant to the regex solution. – Bohemian Jul 02 '22 at 01:50
  • Thanks @Bohemian, I'm aware of that but no language-tag was added and slash is commonly used as a pattern-delimiter (escaped slashes in OP's regex let one conclude its use inside such). So I thought in case of doubt better too much as too little escaping. – bobble bubble Jul 02 '22 at 02:14