Toniq
Toniq

Reputation: 5006

Javascript regex repeated capturing group

I ma trying to match following exact format: '7b3bda24-31db-44d4-aa7f-7012b3594623' but without success.

var reg = new RegExp('/^([a-f0-9]{8})-(([a-f0-9]{4})-){3}([a-f0-9]{12})$/i');

document.getElementById('result').innerHTML = reg.test('7b3bda24-31db-44d4-aa7f-7012b3594623')
<p id="result"></p>

Upvotes: 1

Views: 31

Answers (1)

Unmitigated
Unmitigated

Reputation: 89139

The RegExp constructor accepts a string regular expression (no slashes). If your regular expression is not dynamic, just use a regular expression literal.

const reg = /^([a-f0-9]{8})-(([a-f0-9]{4})-){3}([a-f0-9]{12})$/i;
console.log(reg.test('7b3bda24-31db-44d4-aa7f-7012b3594623'));

Upvotes: 3

Related Questions