Jump to content


Photo

Newbie regex - need new glasses perhaps?


  • Please log in to reply
4 replies to this topic

#1 Braet

Braet
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 24 July 2006 - 12:53 PM

4 hours later and I still can not find where I have gone wrong - nor can I find the answers on my own, so here goes.

My script is not finding matches, the code (well.. in its current incarnation):
preg_match_all("/(.+?) \((.+?)\) \[(.+?)\]\: (.+?)/ims", $winremove, $match3);

A typical line it will be searching:
Jonathan (729) [Title]: Information, perhaps nothing - perhaps run on sentences

the script will echo $winremove for me - actual echo:
Array[];
Array[];
Array[];
Array[];
Jonathan (729) [Title]: Information, perhaps nothing - perhaps run on sentences.
Array

from this code:
echo <<<TESTMATCH
	$match3[1][$i];<BR>
	$match3[2][$i];<BR>
	$match3[3][$i];<BR>
	$match3[4][$i];<BR>
	$winremove<BR>
	$match3
TESTMATCH;

As I'm new to PHP (whoohoo, 5 days now!), I'm quite sure I'm falling under the ID10T ways and it's sitting plain as day in the coding above, but for the life of me I can not see it and hope someone here can.

tia!

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 24 July 2006 - 02:10 PM

The $match3[number][$i] format needs to be changed to {$match3[number][$i]} -- see "Complex syntax" under strings.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 Braet

Braet
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 24 July 2006 - 02:35 PM

ok, I see what you are stating for output - but in case that format was incorrect I also added the $match3 (no info is returning).  What caused me to attempt printing out is that it was not putting the information (once separated) into the db table.  I then set it to print each match, as well as the $winremove variable, and the $match array to see exactly where the issue was.  Changing the echo coding still provides me with a lack of information in $match3 and the variables created from it.

Perhaps I'm just missing something in the information you directed me to, but it seems to me the issue is that it is not finding any matches, there has no data to print (as $match3 should print as $winremove does, no?)

tia!

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 24 July 2006 - 02:50 PM

This works for me:

<?php
	$winremove = 'Jonathan (729) [Title]: Information, perhaps nothing - perhaps run on sentences';
	preg_match_all("/(.+?) \((.+?)\) \[(.+?)\]\: (.+?)/ims", $winremove, $match3);
	echo '<pre>', print_r($match3, true), '</pre>';
?>


Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#5 Braet

Braet
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 24 July 2006 - 03:15 PM

as it does for me, and if I add a little $ in there at the end, it gives me everything I need.  I now officially feel sick that I spent 6 hours focused on the wrong issues - thanks so much, now I can move on to figuring out why it's not going into my db (found 2 other issues based on your info).






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users