سؤال

I'm trying to find two different regex for the following string:

eturk/clock, eturk/vermonster, and noted/noted#42

One of the regex should recognize just the repo (without the issue). So for the first regex, it should just return these matches:

[["eturk", "clock"], ["eturk", "vermonster"]]

And then for the second one, it should recognize the issue along with the repo. So the match would be:

[["noted", "noted", "42"]]


This is what I have so far for the first part:

/(\w*)\/(\w*)?/

This would match like this:

[["eturk", "clock"], ["eturk", "vermonster"], ["noted", "noted"]]

But the thing is, I don't want it to match the reference to the repo with the issue attached. Can anyone offer any help on this?

هل كانت مفيدة؟

المحلول

Regex #1

/\b(\w+)\/(\w+(?!#\d+))\b/

Description

Regular expression visualization

Demo



Regex #2

/\b(\w+)\/(\w+)#(\d+)\b/

Description

Regular expression visualization

Demo

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top