Ionut
Ionut

Reputation: 2858

Javascript match regex against group

Given the following string:

Lorem {{ipsum}} dolor {{sit}} amet

I'm trying to extract thw words ipsum and sit with the following regex:

content = 'Lorem {{ipsum}} dolor {{sit}} amet'
var regexp = /^\\\{\\\{(\w)\\\}\\\}/g;
var match = regexp .exec(content);

The match object returns null. What am I missing? Thanks!

Upvotes: 0

Views: 45

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324610

You have WAY too many backslashes, you're only looking for a single word character, and you're only looking for matches right at the beginning of the string.

var regexp = /\{\{(\w+)\}\}/g;

Upvotes: 2

Related Questions