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

105
Views
Javascript start match function on second character

I'm trying to split a string from the second position in my string which I pass to the function.

Current position:

commandHandler(player: PlayerMp, command: string) {
    if(command.startsWith("/", 0)){
        const cmd = command.match(/\S+/g);
        cmd.forEach(element => console.log(element));
    }
}

If I pass "/test this" to this function then I get the following response: 1) "/test" 2) "this" while I need the following response: 1) "test" 2) "this"

What am I doing wrong?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use slice(1) to remove the first character of the string then proceed as before.

const command = "/test this";

if(command.startsWith("/")){
    const cmd = command.slice(1).match(/\S+/g)
    cmd.forEach(element => console.log(element));
}

about 4 years ago · Santiago Trujillo 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!