Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
hydroxide
Forum Commoner
Posts: 77 Joined: Mon Jun 05, 2006 9:53 am
Post
by hydroxide » Wed Jun 07, 2006 10:44 am
Code: Select all
/(Processing Location\:\s)([A-Za-z\,\s]*)(\<\;)(\D\w\s[a-zA-Z0-9]*\D\D[a-zA-Z0-9\'\:\@]*[$@myels.com]*)(\D\D)([a-zA-Z0-9]*[$@myels.com]*)(<\/a>>\;(<br>)[\s]*<)((\D\w) (href)\D\Dmailto\:[a-zA-Z0-9]*[$@myels.com]*)(\D>)([a-zA-Z0-9]*[$@myels.com]*)(<\/a>>)(<br>)/
REFUSES to match with
Code: Select all
Processing Location: bradenton, <<a href='mailto:rrivera@myels.com'>rrivera@myels.com</a>><br>
<<a href='mailto:faffolter@myels.com'>faffolter@myels.com</a>><br>
It just outputs to the screen 'bradenton,' and that's it. It won't display any more than that. I just can't figure out what's wrong. Any help appreciated.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jun 07, 2006 11:31 am
probably has something to do with this:
sweatje
Forum Contributor
Posts: 277 Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA
Post
by sweatje » Wed Jun 07, 2006 11:54 am
seems pretty odd that you are using \D (any non-numeric character) to match < and '>
What are you really trying to extact from the string?
hydroxide
Forum Commoner
Posts: 77 Joined: Mon Jun 05, 2006 9:53 am
Post
by hydroxide » Wed Jun 07, 2006 12:09 pm
The whole thing, actually. I got rid of using the myels.com thing, but it's still not matching any more than 'bradenton,'
sweatje
Forum Contributor
Posts: 277 Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA
Post
by sweatje » Wed Jun 07, 2006 12:19 pm
I think this may be what you are trying to do, expressed as a
SimpleTest test case:
Code: Select all
function testMatchPreambleAndEmail() {
$str = "some glick
Processing Location: bradenton, <<a href='mailto:rrivera@myels.com'>rrivera@myels.com</a>><br>
<<a href='mailto:faffolter@myels.com'>faffolter@myels.com</a>><br>
more stuff...";
$target = "Processing Location: bradenton, <<a href='mailto:rrivera@myels.com'>rrivera@myels.com</a>><br>
<<a href='mailto:faffolter@myels.com'>faffolter@myels.com</a>><br>";
$regex = "~(Processing Location:\s+\w+,(?:.*?<<a\s+[^>]+.*?</a>><br>){2})~ims";
preg_match($regex, $str, $match);
$this->assertEqual($target, $match[1]);
}
hydroxide
Forum Commoner
Posts: 77 Joined: Mon Jun 05, 2006 9:53 am
Post
by hydroxide » Thu Jun 08, 2006 6:34 am
The problem is, that I'm needing to match records in a large file that contain many entries that follow the same format as that one, only with different information. It wouldn't be possible to enter each one (there's other parts to the file besides this one element) in that function.
sweatje
Forum Contributor
Posts: 277 Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA
Post
by sweatje » Thu Jun 08, 2006 6:46 am
hydroxide wrote: The problem is, that I'm needing to match records in a large file that contain many entries that follow the same format as that one, only with different information. It wouldn't be possible to enter each one (there's other parts to the file besides this one element) in that function.
Ok, so change it to preg_match_all()
Code: Select all
function testMatchPreambleAndEmail() {
$str = "some glick
Processing Location: bradenton, <<a href='mailto:rrivera@myels.com'>rrivera@myels.com</a>><br>
<<a href='mailto:faffolter@myels.com'>faffolter@myels.com</a>><br>
more stuff...
Processing Location: newbradenton, <<a href='mailto:rrivera@myels.com'>rrivera@myels.com</a>><br>
<<a href='mailto:faffolter@myels.com'>faffolter@myels.com</a>><br>
";
$target = array("Processing Location: bradenton, <<a href='mailto:rrivera@myels.com'>rrivera@myels.com</a>><br>
<<a href='mailto:faffolter@myels.com'>faffolter@myels.com</a>><br>"
,"Processing Location: newbradenton, <<a href='mailto:rrivera@myels.com'>rrivera@myels.com</a>><br>
<<a href='mailto:faffolter@myels.com'>faffolter@myels.com</a>><br>");
$regex = "~(Processing Location:\s+\w+,(?:.*?<<a\s+[^>]+.*?</a>><br>){2})~ims";
preg_match_all($regex, $str, $match);
$this->assertEqual($target, $match[1]);
}