F. Vosnim
F. Vosnim

Reputation: 574

How to make non-greedy selection with OR operator?

I wrote a line which makes what I want:

([a-zA-Z0-9]+\.[a-zA-Z]+)\/$

https://coinmarketcap.com/
https://www.buzzfeed.com/
https://www.refinery29.com/
https://www.businessinsider.com/

How can I make the same selection but instead of [a-zA-Z0-9] select anything that starts from // or .?

Upvotes: 0

Views: 26

Answers (1)

Pushpesh Kumar Rajwanshi
Pushpesh Kumar Rajwanshi

Reputation: 18357

You can use this regex,

(?<=\/\/|\.)[^.]+\.[a-zA-Z]+\/$

Explanation:

  • (?<=\/\/|\.) --> Look behind to ensure the text is preceded by either a // or .
  • [^.]+ --> Captures anything except dot
  • \. --> Folowed by a literal dot
  • [a-zA-Z]+\/ --> Followed by one or more letters and a /
  • $ --> End of string

Demo

Upvotes: 1

Related Questions