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
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]+)\`
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.