-4

I am looking for a JavaScript RegEx that matches all woff and woff2 files that start with a particular String, i.e. MyFont.

The following examples should match:

MyFont-bold.woff
MyFont-light.woff2

The following example should not match:

GoogleFont-bold.woff
SomeOtherFont-light.woff2
MyFont-something.css
Krisztián Balla
  • 17,664
  • 13
  • 63
  • 76
Stefan
  • 1,490
  • 3
  • 17
  • 33

1 Answers1

0

^MyFont.*.woff2?$/ would work.

var regex = /^MyFont.*.woff2?$/

console.log(regex.test('MyFont-bold.woff'))
console.log(regex.test('MyFont-light.woff2'))
console.log(regex.test('GoogleFont-bold.woff'))
console.log(regex.test('SomeOtherFont-light.woff2'))
console.log(regex.test('MyFont-something.css'))
NoobTW
  • 2,243
  • 2
  • 23
  • 39