captainill
captainill

Reputation: 2089

Javascript Regex to select text between first colon and optionally either end of line or a second colon

I've been having trouble writing a Regex to grab text starting with a colon and getting everything that follows along with optionally ending when another colon is found. It's for emoji markdown autocompletion. So typing

The expression I have now just grabs everything after the first colon:

const myRe = /\:(.*)$/g;
const result = myRe.exec(inputValue);

Upvotes: 2

Views: 635

Answers (1)

anubhava
anubhava

Reputation: 786011

You can use this regex:

var re = /:([^:]*)/;

and grab captured group #1

RegEx Demo

Upvotes: 3

Related Questions