Regular expression newbie question

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Regular expression newbie question

    How do I write "not" in regular expression? I am new to reg exp. I want to
    check the string which does not contain "http://"

    I wrote /\bhttp:\/\/\b/

    It returns True if the string contains "http://" , however what I want is to
    make it return False when it contains "http://". How do I write it?
    Thanks...




    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    Version: 6.0.576 / Virus Database: 365 - Release Date: 1/30/2004


    Joseph Luner Guest

  2. Similar Questions and Discussions

    1. Very simple regular expression question (ASP/VBScript)
      I need a regular expression pattern that will match repeating "leafs" of XML individually, e.g. <link LinkName="Link1"...
    2. cfform regular expression question
      Hey, Quick question for you. I am trying to use cfform to validate for an email address. How do I do? <cfinput type="text" name="cstreet2" ...
    3. Regular Expression Question
      Hello, is it possible to make a regular expression match for the following situation: I have a string, looking like 'foobarbarbar'. I don't...
    4. Regular Expression - BackReferences Question
      I have a file containing the following URL in it http://www.somesite.com/folder/1.gif Now, everyday I need to run a script so that 1.gif in the...
    5. [PHP] Regular expression question
      well, first off '>' should not be allowed as a value of an attr="" pair anyways. You should convert it to &gt; or &lt; this will solve that problem....
  3. #2

    Default Re: Regular expression newbie question

    Joseph Luner wrote:
    > How do I write "not" in regular expression? I am new to reg exp. I want to
    > check the string which does not contain "http://"
    >
    > I wrote /\bhttp:\/\/\b/
    >
    > It returns True if the string contains "http://" , however what I want is to
    > make it return False when it contains "http://". How do I write it?
    > Thanks...
    >
    >
    >
    >
    > ---
    > Outgoing mail is certified Virus Free.
    > Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    > Version: 6.0.576 / Virus Database: 365 - Release Date: 1/30/2004
    >
    >
    Don't use a regular expression for that, it's not needed strpos would be
    faster.


    if (!strpos("http://www.php.net", "http://") === FALSE)
    echo "http:// not found in string";
    else
    echo "http:// found in string";


    this will obviously echo http:// found in string
    Cameron Guest

  4. #3

    Default Re: Regular expression newbie question

    Cameron wrote:
    > Joseph Luner wrote:
    >
    >> How do I write "not" in regular expression? I am new to reg exp. I
    >> want to
    >> check the string which does not contain "http://"
    >>
    >> I wrote /\bhttp:\/\/\b/
    >>
    >> It returns True if the string contains "http://" , however what I want
    >> is to
    >> make it return False when it contains "http://". How do I write it?
    >> Thanks...
    >>
    >>
    >>
    >>
    >> ---
    >> Outgoing mail is certified Virus Free.
    >> Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    >> Version: 6.0.576 / Virus Database: 365 - Release Date: 1/30/2004
    >>
    >>
    >
    > Don't use a regular expression for that, it's not needed strpos would be
    > faster.
    >
    >
    > if (!strpos("http://www.php.net", "http://") === FALSE)
    > echo "http:// not found in string";
    > else
    > echo "http:// found in string";
    >
    >
    > this will obviously echo http:// found in string

    Err sorry, ignore the ! bfore strpos

    ~Cameron
    Cameron Guest

  5. #4

    Default Re: Regular expression newbie question

    I know I can do it with strpos, but I need to use regular expression. Would
    you tell me how?

    To be exact, I am using a library called Vdaemon (a .NET like form
    validation library via XML for PHP, it's very very cool)
    [url]http://www.x-code.com/vdaemon_web_form_validation.php[/url]




    "Cameron" <foo@bar.invalid> wrote in message
    news:bvkikl$7ch$1@news5.svr.pol.co.uk...
    > Joseph Luner wrote:
    > > How do I write "not" in regular expression? I am new to reg exp. I
    want to
    > > check the string which does not contain "http://"
    > >
    > > I wrote /\bhttp:\/\/\b/
    > >
    > > It returns True if the string contains "http://" , however what I want
    is to
    > > make it return False when it contains "http://". How do I write it?
    > > Thanks...
    > >
    > >
    > >
    > >
    > > ---
    > > Outgoing mail is certified Virus Free.
    > > Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    > > Version: 6.0.576 / Virus Database: 365 - Release Date: 1/30/2004
    > >
    > >
    >
    > Don't use a regular expression for that, it's not needed strpos would be
    > faster.
    >
    >
    > if (!strpos("http://www.php.net", "http://") === FALSE)
    > echo "http:// not found in string";
    > else
    > echo "http:// found in string";
    >
    >
    > this will obviously echo http:// found in string

    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    Version: 6.0.576 / Virus Database: 365 - Release Date: 1/30/2004


    Joseph Luner Guest

  6. #5

    Default Re: Regular expression newbie question

    PHPEdit has a nice RegExpEditor tool

    [url]http://www.phpedit.net/products/RegExpEditor/[/url]




    "Joseph Luner" <J0s4phLun3r_N0SPAMMM@yahoo.com> wrote in message
    news:RgjTb.94314$9Ce1.89193@news04.bloor.is.net.ca ble.rogers.com...
    > How do I write "not" in regular expression? I am new to reg exp. I want
    to
    > check the string which does not contain "http://"
    >
    > I wrote /\bhttp:\/\/\b/
    >
    > It returns True if the string contains "http://" , however what I want is
    to
    > make it return False when it contains "http://". How do I write it?
    > Thanks...
    >
    >
    >
    >
    > ---
    > Outgoing mail is certified Virus Free.
    > Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    > Version: 6.0.576 / Virus Database: 365 - Release Date: 1/30/2004
    >
    >

    Duyet The Vo Guest

  7. #6

    Default Re: Regular expression newbie question

    "Joseph Luner" <J0s4phLun3r_N0SPAMMM@yahoo.com> writes:
    > How do I write "not" in regular expression? I am new to reg exp. I want to
    > check the string which does not contain "http://"
    >
    > I wrote /\bhttp:\/\/\b/
    >
    > It returns True if the string contains "http://" , however what I want is to
    > make it return False when it contains "http://". How do I write it?
    > Thanks...

    <?php
    error_reporting(E_ALL);

    $str1 = "http://google.com";
    $str2 = "google.com";

    if (preg_match("/\bhttp:\/\/\b/", $str1))
    {
    echo "str1 matches http\n";
    }
    else
    {
    echo "str1 doesn't match http\n";
    }

    if (preg_match("/\bhttp:\/\/\b/", $str2))
    {
    echo "str2 matches http\n";
    }
    else
    {
    echo "str2 doesn't match http\n";
    }

    if (! preg_match("/\bhttp:\/\/\b/", $str1))
    {
    echo "str1 doesn't match http\n";

    }
    else
    {
    echo "str1 matches http\n";
    }

    if (! preg_match("/\bhttp:\/\/\b/", $str2))
    {
    echo "str2 doesn't match http\n";
    }
    else
    {
    echo "str2 matches http\n";
    }

    ?>

    --
    The guy's a troll. Ignore him. -- Captain Jean-Luc Picard
    The guy's not even the real Jean-Luc Picard. Ignore him. -- Etienne Rouette
    [url]http://beable.com/[/url]
    Beable van Polasm Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139