0

I'm trying to write a Regular Expression to extract names from an HTML table, where the names are written in the following format: "Smith, Bob"

The regular Expression I'm using is: [a-zA-Z]*,\s[a-zA-Z]*

I keep getting the following error message when executing the code (in the second preg_match_all line): Unknown modifier '*'

I have changed the * to a +, only for the same error prompt. My code is the following:

$start = strpos($content,'<table cellspacing="0" cellpadding="2" rules="all" border="1"             id="gvChart"'); 
$end = strpos($content,'</table>',$start) + 8;
$table = substr($content,$start,$end-$start);

/* Regex */
preg_match_all("|<tr(.*)</tr>|U",$table,$player);
foreach ($player as $val) {
preg_match_all("[a-zA-Z]*,\s[a-zA-Z]*", $table, $name);
echo $name[0];
}

All Help would be much appreciated here, Thanks :)

Sven
  • 69,403
  • 10
  • 107
  • 109
mkayen
  • 27
  • 5
  • 1
    I don't like to say it, but what about "O'Brian, Miles", or "Kennedy, John F."... – Sven Oct 01 '13 at 08:06

1 Answers1

1

you must use a delimiter in your function... Try:

preg_match_all("/[a-zA-Z]*,\s[a-zA-Z]*/", $table, $name);

or even:

preg_match_all("/[A-Z]*,\s[A-Z]*/i", $table, $name);
Enissay
  • 4,969
  • 3
  • 29
  • 56