1

Update to clarify question

I'm trying to use RegEx to find text within single backticks (i.e. inline code in Markdown format). I'm doing this to implement a RegEx-based Markdown parser in Xojo. I've tried a few patterns but they all seem to return all (or part of) the content of text within a code fence (triple backticks).

Given this Markdown

This is `inline code` (obviously).

Here is a code fence:

```
Some code
blah blah
```

Another `example for you`.

another fence:

```json
{"title":"Hello World!"}
```

I want to find the following matches:

`inline code`
`example for you`

Using this RegEx pattern: `(.*?)`

Matches the inline code correctly but also matches the first two backticks of each code fence.

Can someone help me to figure out how to only match the content between single backticks but exclude from the match empty space between two backticks?

3
  • Give us examples and more detail. Commented Dec 22, 2016 at 1:58
  • Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! See also: How to Ask Commented Dec 22, 2016 at 8:03
  • From my experience with markdown parsing: Take out the fenced blocks before you do anything else, replace by unique keys, then reinsert them at the end. Commented May 12, 2022 at 10:28

2 Answers 2

3

OK. After a lot of head scratching, this seems to work:

\`([^\`].*?)\`

Hope it helps someone.

Sign up to request clarification or add additional context in comments.

Comments

2

I think you can use a regex like this:

/`([^`\n\r]+)`/g

By giving group \1

[Regex Demo]

And if your RegEx supports Positive Look-behind You can use this:

/(?<=`)[^`\r\n]+(?=`)/g

[Regex Demo]

1 Comment

Quoting OP: It doesn't "exclude from the match empty space between two backticks"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.