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

241
Views
Some regular expressions I've been studying

I've found these regex elsewhere:

myString.replace(/^.*\//, '');
myString.replace(/\..*?$/, '');

My question is:

  • do ^ and ?$ make any sense here?

And my interpretation is that ^ isn't relevant, because we are using .* which means "anything".

The second one means replace from the . any character in lazy mode till the end of the string. Which is the same as nothing.

So I'd write them:

myString.replace(/.*\//, '');
myString.replace(/\..*/, '');

But I am not 100% sure as my Regex is quite basic. Ideas?

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

0

Indeed, in the first regular expression the ^ is not really needed. The effect is the same without it.

However, in the second regular expression there is a difference when you omit the ? and the $, because . does not match newline characters (unless you add s as modifier).

See the different results:

let myString = `.this
is multiline`;


console.log(myString.replace(/\..*?$/, ''));

console.log(myString.replace(/\..*/, ''));

about 4 years ago · Juan Pablo Isaza Report

0

And my interpretation is that ^ isn't relevant, because we are using .* which means "anything".

Yep, that's the start of the string, but if you're wanting all of the string it has no relevance. Also, go here for a great regex playground.

do ^ and ?$ make any sense here?

To answer the second question, for regex /\..*?$/, the ?$ does not make sense with *, b/c x* means 0 or more of x and x? means 0 or 1 (unless you intentionally wanted 0 or 1 of 0 or more, but doubt that). This is taken directly from the help sheet on regexr.com. enter image description here

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!