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

248
Views
Regex, matching backticks not nested within triple backticks

I'm trying to match strings that are surrounded by backtick's but they aren't surrounded by triple backtick's.

For example:

match: `I should be matched`

should not match: ``` `Hello world` ```

This is what I've tried so far: https://regex101.com/r/P4MhiM/1

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

0

i get pass this test case

first capture all match in single quote

\`(?:.+)\`

second filter the matchs only char not backticks nor white space

\`(?:[^\`||\s]+)\`

https://regex101.com/r/oVE7zi/1

about 4 years ago · Juan Pablo Isaza Report

0

Match and capture a part of the match, then use custom logic in the replacement:

const text = "\n``` `Hello world` ```\n\n\n`Matched!`\n";
const rx = /```.*?```|`([^`\n]+)`/g;
console.log(
  text.replace(rx, (x, y) => y ? `<code>${y}</code>` : x)
)

See the regex demo. Details:

  • ```.*?``` - strings between triple backticks (with no line breaks in between backticks)
  • | - or
  • `([^`\n]+)` - strings between backticks without line break chars.
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!