[PHP] Re: Reg exp help

2002-08-30 Thread Erwin

> Take for example:
>
> 194.236.30.24 - - [30/Aug/2002:11:46:29 +0200] "GET
> /bildgalleri/createjpg.php?url=/v044&file=v044_27.jpg HTTP/1.1" 200
> 8874
> 217.215.84.222 - - [30/Aug/2002:11:46:39 +0200] "POST /weblogg.php
> HTTP/1.1" 200 3149488

[more loglines]

>
> Here I'ld like to remove all lines that looks like 217.215.84.222 some
> text ending with line breakĀ…
>
> How should the reg exp look?

Try this: preg_replace( "/^217.215.84.222.*\n/m", "", $log )
The second argument, currently empty, can be used as a replacement string.

As we look at the regular expression "/^217.215.84.222.*\n/m", from left to
right:
^ Start of line if modifier /m is used (completely right)
, followed by a dot (.). This dot means any characters, followed
by a asterisk (*). The asterisk is a "0 or more quantifier", which matched
everything until the next statement (in this case the "\n").

You can also use "$" instead of "\n", only the newline will not be stripped.
"$" means end of line, while "\n" means newline.

HTH, Erwin



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: reg exp help

2001-07-23 Thread James Holloway

Hi Justin,

for the username, you can use:

if (!preg_match("/^[a-z0-9]*$/", $username)) {
// error
} else {
// ok
}

The ^ means start of the string, the characters between the [ and ] are ones
that we want, the * means however many times, and the $ means the end of the
line / string.  So if there isn't a match against lower case letters and
numbers throughout the string (from start to finish), there's an error.

I'd advise you to go more complex with the email address.

James.

"Justin French" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> hi all,
>
> two quick reg exp problems:
>
> one:
> $username must only contain a-z lowercase, 0-9, no spaces, no other
characters.
> what would the regexp be?
>
> if(ereg("", $username)) { $valid = "yes" } else { $valid
> = "no")
>
>
> two:
> i want to do a really small email validation, just to make sure the
> email probably right, as in:
> [EMAIL PROTECTED]
>
> what's the best reg exp to use.
>
>
> i'm aware there are email validating script out there, but I want to
> learn for myself
>
>
>
> many thanks in advance
>
>
> justin french



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]