-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
  • 19,223
  • 13
  • 68
  • 84
Stefan
  • 1,590
  • 3
  • 18
  • 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,466
  • 2
  • 24
  • 42