Re: Reg exp help
| From: | Erwin | Date: | Fri, 30 Aug 2002 12:39:00 +0000 |
| Subject: | Re: Reg exp help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-114644@lists.php.net to get a copy of this message | ||
> 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)
<ip address>, 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