Reputation: 453
I'm having a hard time matching multiple patterns in my regex and I'm wondering what could be wrong.
My test string: https://api.github.com/repos/baxterthehacker/public-repo/releases/1261438
These work as expected:
/https:\/\/api\.github\.com\/repos\/
Matches: https://api.github.com/repos/
/\/releases\/.*
Matches: /releases/1261438
My question is how do I combine the two into one statement? This is what I've tried but it only matches the first pattern and not the second for some reason.
/(https:\/\/api\.github\.com\/repos\/)|(\/releases\/.*)/
Matches: https://api.github.com/repos/
What am I doing wrong? Why is the second pattern ignored?
Upvotes: 0
Views: 7250
Reputation: 1337
The |
is an OR operator for regex. It does not do concatenation. Try removing the |
character from your regex string and see the magic.
The regex /(https:\/\/api\.github\.com\/repos\/).*(\/releases\/.*)/
does the trick.
Upvotes: 1