DroidOS
DroidOS

Reputation: 8880

WOFF matching regex

I am trying to validate each of the font names in a WOFF link such as

<link href='http://fonts.googleapis.com/css?family=Anonymous+Pro:400,700italic,400italic,700|Radley:400,400italic' rel='stylesheet' type='text/css'>

by using the following bit of code

<?php
$woff = 'Oswald:400,600,700Italic';
$f = preg_match('/^([a-zA-Z0-9+]{1,20}):{0,1}(([1-9]00(italic){0,1},{0,1}){0,3})/',$woff);
echo ($f);
?>

which does the job pretty well. However, I am by no means a RegEx expert so I suspect that my regex is a pretty naive one. Any help with polishing it up would be much appreciated.

Upvotes: 1

Views: 165

Answers (1)

Sly
Sly

Reputation: 1165

Matching Anonymous+Pro:400,700italic,400italic,700 with this regex:

/([^:]+) *: *((?:[\d\w]+,*)+)/

Returns:

> test.match(/([^:]+) *: *((?:[\d\w]+,*)+)/)
[ 'Anonymous+Pro:400,700italic,400italic,700',
  'Anonymous+Pro',
  '400,700italic,400italic,700',
  index: 0,
  input: 'Anonymous+Pro:400,700italic,400italic,700' ]

Would be helpful to see what you're expecting the output to be.

Upvotes: 1

Related Questions