1

I have 2 cases of outcome of a string, and I want to get the numbers out of it.

The first one is <@&!302050872383242240>
And the second one is <@&302050872383242240>

Is it possible to get only the numbers of this regex or remove <@&!> and <@&> out of this string?

Lmao 123
  • 111
  • 1
  • 8
  • How better do you want me to explain this? (whoever downvoted). I don't know what else you need except a string. Holy damn lol. – Lmao 123 May 19 '20 at 15:35
  • 1
    You know the problem is that you are supposed to give us the code you tried. We are not expected to just produce it for you, ps. I didn't downvote you – Gaurav Mall May 19 '20 at 15:37
  • I'll take a look, thanks @Vickel – Lmao 123 May 19 '20 at 15:45
  • Next time, try to post what you tried. The reason being, sure you have a problem, but at least you're showing research and effort, people can also point to some specific problem in your code, and not make Stack Overflow become a free coding service. Given the simplicity of the task, not that grave, but just as a reminder, read [ask] – Roko C. Buljan May 19 '20 at 15:53
  • @Lmao123 For some reason I agree with you, I always upheld that idea. If you don't have all the ingredients of a recipe, you shouldn't show what you did with half of them. But rules are rules and we have to follow the guidelines of this site :) – Gaurav Mall May 19 '20 at 18:02

1 Answers1

2

Try:

^<@&\!?(\d+)>$
  • ^ asserts position at start of a line
  • \!? matches the character ! literally (case sensitive)
  • ? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed
  • 1st Capturing Group (\d+)
    • \d+ matches a digit (equal to [0-9])
    • + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed

Demo

Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225