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

173
Views
How do I separate tags in a string

I am currently using .split to try to split a string into different 'tags'.

let text = "@yusra is cool @zain @chris is cool";
const myArray = text.split("@");
console.log(myArray);

The code above gives this output:

Array ["", "yusra is cool ", "zain ", "chris is cool"]

the expected output is:

Array ["yusra", "zain ", "chris"]

How do I modify this to make it do what I want.

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

0

You could try something like this:

let text = "@yusra is cool @zain @chris is cool";
const myArray = text.split(" ").filter(s => s.startsWith("@")).map(s => s.substring(1));
console.log(myArray);

about 4 years ago · Juan Pablo Isaza Report

0

Instead of using split you can use match to find the tags via a regex.

let text = "@yusra is cool @zain @chris is cool";
const myArray = text.match(/@\w+/g);
console.log(myArray);

about 4 years ago · Juan Pablo Isaza Report

0

Use match with a regex. Here we match @ and then one or more lowercase letters between "a" and "z".

const text = "@yusra is cool @zain @chris is cool @bob";
console.log(text.match(/@[a-z]+/g));

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!