www.webdeveloper.com
Results 1 to 6 of 6

Thread: regular expressions problem

  1. #1
    Join Date
    Dec 2011
    Posts
    28

    regular expressions problem

    Hi all,

    I want replace all occurances of " dot " by .<br />

    I used this code
    $clean_db_text = str_replace(".", ".<br />", $clean_db_text);

    But , it caused problems , when it find www.domain.com , It replaces them.I don't need that . I only want any other dot to be replaced.

    I tried :

    $pattern = "[^www]\.[^com]";
    $replace = ".<br />";
    $clean_db_text = preg_replace($pattern, $replace, $clean_db_text);


    But I got the following error :
    Warning: preg_replace(): Unknown modifier '\' in D:\xampp\htdocs\alaa\test_regex.php on line 16

    Can someone help ?

  2. #2
    Join Date
    Dec 2011
    Posts
    28
    I just wanted to say by regular expressions , any . not preceeded by "www" and not followed by "com" or "net"

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,355
    PHP Code:
    $pattern '/(?<!www)\.(?!com)/i' 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Dec 2011
    Posts
    28
    Nice ! worked..

    Thank you .

    But that worked only for .com , How can I make it working for .com and .net .org ?

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,355
    (?!com|net)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Dec 2011
    Posts
    28
    thank u v. much

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles