Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
How would I get a discord tag from a string with regex?

I don't have basically any experience when it comes to regex, and have a basic understanding of string manipulation. I am trying to separate a discord tag from the rest of a string, but am running into issues.

For example, I was able to separate a tag like vunsh#3191 from 'vunsh#3191 has done blah blah blah`. But when a discord tag has a space in it or other characters, it doesn't detect it with the system I'm using right now.

Ex. My current system would get just vunsh's from vunsh's discord#1234 blah blah blah. I need vunsh's discord#1234

I found a method called string#match(), and it seems to be what I am looking for. What I am struggling with is what to put as the regex pattern that passes into #match().

Ex.

const paragraph = 'vunsh thing#2134 blah blah';
const regex = //what goes here?
const found = paragraph.match(regex);

console.log(found);
// expected output: Array ["vunsh thing#2134"]

Note: Not all the strings I am working with contain the word "vunsh", but all discord tags have a # and 4 numbers right after that.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could use

const regex = /.*#\d{4}\b/g;

But this wont work in all cases where theres text before the username, for that there is no solution.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!