lowlypalace
lowlypalace

Reputation: 157

Regex to mach Github commit URL.

I'm quite new to regex and I'm trying to create a regular expression that matches commit URL on GitHub, for example, a string like this should be matched:

https://github.com/torvalds/linux/commit/8dc765d438f1e42b3e8227b3b09fad7d73f4ec9a

Is this a correct way to do this?:

https://github.com/.*/.*/commit/[0-9a-f]{40}

I only need to match links starting with 'https'.

Upvotes: 0

Views: 890

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522094

Your pattern is fine, but you could make it more generic by allowing any number of paths between the domain and the commit ending portion:

https://github\.com(?:/[^/]+)*/commit/[0-9a-f]{40}

Demo

Upvotes: 1

Related Questions