Parsing SSI style directive with regular expression

A

Anonymous

Guest
Hi,

I'm trying to parse what is effectively a just structured HTML comment (similar format to an SSI directive) and extract sections of it using a regular expression.

I'm trying to parse something like:
Code:

The regex should first of all validate that the format is correct and then extract the type and value.

The code I'm using is as follows.
Code:
<?eregi("^$", "", $registers);
print_r($registers);

If it worked, it would print:
Code:
Array
(
    [0] => 
    [1] => type
    [2] => value
)

I'm not very good with regular expressions. I'm trying to figure them out but just when I think I'm getting somewhere it all goes to pot and refuses to work.

I've simplified it down two two statements. The first one works, (i.e. returns some registers) the second fails.
Code:
<?eregi("^$", "", $registers);
print_r($registers);
Code:
<?eregi("^$", "", $registers);
print_r($registers);

Please help!

Thanks,

Matt
 
if you already have your solution, where is the problem, the last regex ?
 
I don't have the solution. The last two regexes are cutdown versions of the main (first) one. I was trying to build it up step by step. The first of the bottom two regexes works, but as soon as I do the next step (add in the #) it fails. I tried matching other characters in place of the hash (and adjusting the input string appropriately) but as soon as I put any character in there it fails.

The last two regexes were just me trying to identify where the problem may be. The full regex that I'm trying to get working is:

Code:
<?php
eregi("^$", "", $registers);
print_r($registers);
 
I never use POSIX expression, rather Perl's. I can imagine that # has a special meaning and thus makes your second regexp invalid.

In Perl regexp's, I would do this:

Code:
<?php
$someData = '';
if (preg_match("//", $someData, $someDataInfo)) {
   $type = $someDataInfo[1];
   $value = $someDataInfo[2];
} else {
   print "Invalid";
}
?>

Coditor
 
Back
Top