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

159
Views
javascript regex [-_.] not first character

I do not want the first letter of these characters _-. Used but can use between characters

'(^[a-zA-Z0-9-_. ]*$){1,10}'
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If [a-zA-Z0-9-. ] is the allowed range of characters, should be present 1-10 times and can not start with - or . then you don't need lookarounds.

You can match the first character [a-zA-Z0-9 ] and repeat the fully allowed range 0-9 times.

^[a-zA-Z0-9][a-zA-Z0-9. -]{0,9}$

See a regex demo.

If an underscore is also allowed, you could shorten the pattern using \w:

^[a-zA-Z0-9][\w. -]{0,9}$
about 4 years ago · Juan Pablo Isaza Report

0

I tweaked with some tools online and the follwoing do should do the job fine:

const regex = /^[^\_\-\.]{1}(.)*/gm;
const str = `.awdawd`;
let m;

while ((m = regex.exec(str)) !== null) {
    // This is necessary to avoid infinite loops with zero-width matches
    if (m.index === regex.lastIndex) {
        regex.lastIndex++;
    }
    
    // The result can be accessed through the `m`-variable.
    m.forEach((match, groupIndex) => {
        console.log(`Found match, group ${groupIndex}: ${match}`);
    });
}

I also recommend using the website regex101.com if you wanted to play around with the Javscript regex.

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!