Reputation: 157
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
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}
Upvotes: 1