Hello!
I've come across a little problem with Regex, I was hoping someone might see the problem off hand.
Here is some sample content I am searching through, It's the gameshark codes for PEC:
#Ace Combat 3 Electrosphere#SLPS-02021#SLPS-02020
§N Joker Command
D00BF32E ????
"Infinite Time for battle
D0054332 2442
80054332 2402
#Name of Game#SLUS-Number#Second-Slus-num
"Code Folder/Name of Code (codes in hex)
abcdef01 2345
6789ABCD EF12
.This line is a comment
I am trying to write a PHP script to organize the codes. You have to edit the 4MB+ txt file to add or remove codes, it's a pain. I was hoping to make life easier for myself and anyone who might want to upload existing code list, Add codes to database, compile a custom code list, and allow the user to save the custom file.
This project will be open source under a CC license!
I am working to import the existing code list at the moment. Here is what I have:
//Open code list
$file = "./codelist.inf";
$fh = fopen($file, 'r');
$codes = fread($fh, filesize($file));
fclose($fh);
//Match Game Title
$mg = "(#[A-Za-z0-9\-\ ]{1,200}(#[A-Za-z0-9\-\ ]{1,25}){1,3})";
//Match Codes
$mc = "[A-Fa-f0-9\ ]{13}";
//Matches Codes Names
$mcn = "\"[A-Za-z0-9\ \-\\\\]{1,}";
//Do Matches
preg_match_all($mg, $codes, $return);
print_r($return);
Here is the problem: I can match the Game title, match codes and the Code Names expressions individually, but I can't seam to get them to work together.
I am open to other possibilities, though I would like to see how regex can do it. Ultimately I just need to separate the file at each game title into an array.
Goal output might look like this:
Array
(
[0] => Array(
#Ace Combat 3 Electrosphere#SLPS-02021#SLPS-02020
§N Joker Command
D00BF32E ????
"Infinite Time for battle
D0054332 2442
80054332 2402
)
[1] => Array(
#Name of Game#SLUS-Number#Second-Slus-num
"Code Folder/Name of Code (codes in hex)
abcdef01 2345
6789ABCD EF12
)
)
Right now I have:
preg_match_all('/(#[A-Za-z0-9\-\ ]{1,200}(#[A-Za-z0-9\-\ ]{1,25}){1,3})/ism', $codes, $return);
and when I add a new line \n to the end (before the /ism) it no longer matches the game titles but returns a few empty arrays.
preg_match_all('/(#[A-Za-z0-9\-\ ]{1,200}(#[A-Za-z0-9\-\ ]{1,25}){1,3})\n/ism', $codes, $return);
Is there an alternative to \n, am I using it wrong? I thought that I could do this:
//Match Game Title
$mg = "(#[A-Za-z0-9\-\ ]{1,200}(#[A-Za-z0-9\-\ ]{1,25}){1,3})";
//Match Codes
$mc = "[A-Fa-f0-9\ ]{13}";
//Matches Codes Names
$mcn = "\"[A-Za-z0-9\ \-\\\\]{1,}";
//Do Matches
preg_match_all("($mg)\n(($mc|$mcn)\n){2,}", $codes, $return);
print_r($return);
But, alas, to no avail!
How might I go about combining the 3 expressions so that it returns the game titles, code names and codes, etc?
Thanks for the help!