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

158
Views
Write a regular expression that finds strings of the following kind

The task itself looks like this: Given string 'ave a#b a2b a$b a4b a5b a-b acb'. Write a regular expression that finds strings of the following kind: the letters 'a' and 'b' are at the edges, and there is neither a letter nor a number between them.

It's just really hard for me to make sense of it. But I was able to write something like:

'ave a#b a2b a$b a4b a5b a-b acb'.replace(/a\Wb/g, ""),

but it works by replacing only the values I need to output and leaving 'ave a2b a4b a5b acb', but I just need to remove everything except 'a#b a$b a-b'. Can you help me with that?

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

0

You can match all occurrences of the \ba[^\sa-zA-Z0-9]b\b pattern that matches a not preceded with any word char, then any char other than whitespace, letters and digits, and then a b not followed by a word char, and then join the output with a space:

console.log(
  'ave a#b a2b a$b a4b a5b a-b acb'.match(/\ba[^\sa-zA-Z0-9]b\b/g).join(" ")
)

See the regex demo.

Note: if the expected matches occur in between whitespaces or start/end of string, you might need to replace word boundaries with whitespace boundaries, /(?<!\S)a[^\sa-zA-Z0-9]b(?!\S)/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!