Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #18904
| Path | csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | "J.O. Aho" <user@example.net> |
| Newsgroups | comp.lang.php |
| Subject | Re: question about |
| Date | Mon, 4 Apr 2022 14:26:01 +0200 |
| Lines | 32 |
| Message-ID | <jb06eqFiv7oU1@mid.individual.net> (permalink) |
| References | <sv5hqt$h8m$1@gioia.aioe.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Trace | individual.net 6PS+ORLGkNnBo/8dHeHqNwau3xfO8qOJ09N5qs82wpMvhEo91q |
| Cancel-Lock | sha1:QtNW5/rsIAUfI0H47Ab4QEEUBl4= |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 |
| Content-Language | en-US-large |
| In-Reply-To | <sv5hqt$h8m$1@gioia.aioe.org> |
| Xref | csiph.com comp.lang.php:18904 |
Show key headers only | View raw
On 23/02/2022 15.54, alex wrote:
> $ echo center | sed -E 's#(.*)#start-\1-end#'
> start-center-end
>
> I tried to do the same thing with php, but the result is different
>
> $ php -r "echo preg_replace('#(.*)#', 'start-\0-end', 'center') . PHP_EOL;"
> start-center-endstart--end
> ^^^^^^^^^^
>
> Why?
Why I'm not sure, but figured out two solutions:
You set a number a limit to the replacement
$ php -r "echo preg_replace('#(.*)#', 'start-\1-end', 'center', 1) .
PHP_EOL;"
or you can tell that it's from the beginning of the row
$ php -r "echo preg_replace('#^(.*)#', 'start-\1-end', 'center') . PHP_EOL;
I would guess this has to do with the end of char array \0 (internally)
and it's counted as a white space, so it's not included in the first
match, but then as the second match, but that is just a wild guess.
--
//Aho
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
question about alex <1j9448a02@lnx159sneakemail.com.invalid> - 2022-02-23 15:54 +0100
Re: question about Kristjan Robam <he6655442211@hotmail.com> - 2022-04-04 04:06 -0700
Re: question about "J.O. Aho" <user@example.net> - 2022-04-04 14:26 +0200
Re: question about Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2022-04-04 13:07 +0000
Re: question about Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2022-04-04 13:29 +0000
csiph-web