Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: regex problem

  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts

    regex problem

    Hi,

    PHP Code:
    <?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!
    PHP 5 & MySQL 5 (Y)

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by marek_mar View Post
    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!
    PHP 5 & MySQL 5 (Y)

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    preg_split?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •