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

199
Views
Match everything except the digit and space in the very beginning

The target string looks like a number followed by a space and then followed by one or more letters, e.g. 1 Foo or 2 Foo bar.

I can use [^\d\s].+, but it doesn't work for single letters, e.g. 3 A.

What can be done here?

https://regexr.com/6io06

The workaround I use currently is to use replacing instead of matching.

from  \d\s(.+)
to    $1

But as a purist I prefer to use replacing if and only if we don't mean "replace something with nothing". When we need to replace something with nothing, I would prefer to use matching.

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

0

Just remove the square brackets. The square brackets alone indicate "any of this set", so you are matching either \d or \s. When you also add a ^ inside you are not indicating the beginning of the string, but you are negating the set. So, summing up, your regular expression means:

Match a single character that may be everything except a digit and a white space, then match everything.

If you remove the square brackets you will match \d followed by \s, and the ^ symbol will mean "beginning of the string".

/^\d\s(.+)/
about 4 years ago · Juan Pablo Isaza Report

0

I prefer using a regex replacement here:

var input = ["1 Foo", "2 Foo Bar", "No Numbers Here"];
var output = input.map(x => x.replace(/^\d+ /, ""));
console.log(output);

about 4 years ago · Juan Pablo Isaza Report

0

If I didn't misread your question, this might be what you want:
exclude capture the number and space at the beginning

https://regexr.com/6io1m

(?!^\d+)(?!\s+).*

This matches 1 Foo Bar to Foo Bar and 3 A to A

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!