Skip to content

Regex - cannot match inline token if it is surrounded by text. #3418

Answered by ivanjaros
ivanjaros asked this question in Q&A
Discussion options

You must be logged in to vote

ah, this worked:

const rating = {
  name: 'rating',
  level: 'inline',
  start(src) { return src.match(/[1-5]\*/)?.index; }, <-- no caret
  tokenizer(src) {
    const match = src.match(/^([1-5])\*/); <--- caret
    if (match) {
      return {
        type: 'rating',
        raw: match[0],
        rating: parseInt(match[1]),
      };
    }
  }
};

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ivanjaros
Comment options

@ivanjaros
Comment options

Answer selected by ivanjaros
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants