...

View Full Version : regex problem



kaisellgren
05-30-2007, 05:58 PM
Hi,


<?php

$a = "Hosting is most certainly a business that companies/people can profit in. I'm not questioning that -- my point is that you're expecting an awful lot for the amount you pay. You wouldn't offer 1 on 1 livechat, phone support or e-mail responses in 15 minutes for what you pay your host per hour. You expect them to. That doesn't mean you're not somehow 100% pure profit to them (in fact you could be if they do things right) BUT you're paying less than nothing. Be nice to the technicians who are helping you, thank them -- and let them know you'll google next time or post on their forums instead.";
preg_match_all("/(.{0,200}\bnot\b.{0,200})/ism",$a,$matches);
foreach ($matches[1] as $key)
{
echo $key.'<br />';
}

?>

This does not give me two lines of text containing both 403 chars like my regex clearly says 200 + 200 + 3 = 403 chars!

marek_mar
05-30-2007, 06:17 PM
You forgot to ask the question.
Also the regex does not ask for 403 characters... it asks for 0 to 200 characters, then a "not" and then another 0 to 200 characters.

kaisellgren
05-30-2007, 06:19 PM
You forgot to ask the question.
Also the regex does not ask for 403 characters... it asks for 0 to 200 characters, then a "not" and then another 0 to 200 characters.
Look.

I have a big text that has two 'not' words. I want to get 200 chars around both sides of ALL 'not' words.

Now my regex does not do it. It gets something like over 100 chars or so.

If I change {0,200} to {200}, then I get only 1 result although I have two 'not' words in my text! :(

rafiki
05-30-2007, 07:49 PM
preg_split?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum