Regex to match emoji

I’m having trouble getting this regex to work in Drafts

Example heading in draft

# 🧭 Project Name

I’m trying set a variable dependent on the presence of the draft beginning with "# " followed by one of these emoji :compass::package::fire::rocket::calendar:

I’m using this to try to capture the emoji and whatever text follows it on the first line:

This worked in browser

/# ([\u{1F9ED}\u{1F4E6}\u{1F525}\u{1F680}\u{1F4C6}] .*)/

but Drafts doesn’t match the unicode emoji.

I also tried this notation but that didn’t work either

/# ((\u1F9ED|\u1F4E6|\u1F525|\u1F680|\u1F4C6) .*)/

Additionally, I’m having trouble with the backreference — I want $1 only — but when I do get it to match it returns the entire matched string followed by a period and the capture group like this:

# 🧭 Project Name.🧭 Project Name

What am I doing wrong?

Try this:

function grabTitle()
{
	return draft.content.match(/# ((\u{1F9ED}|\u{1F4E6}|\u{1F525}|\u{1F680}|\u{1F4C6}) .*)/u)[1];
}

alert(grabTitle());

Note, the use of the u flag to enable the Unicode matching (and the lack of the g flag for global matching to allow the group matches to be returned), and that match() is returning an array (which was why you were getting concatenation of differing results in your earlier output - you were outputting the array of results rather than the one result you wanted).

Hope that helps.

Amazing! That worked great, thank you!!! … (I had a hunch about the array thing but when I tried adding the index [1] before it didn’t work for me)