S
S
sorry_i_noob2018-07-04 20:15:47
PHP
sorry_i_noob, 2018-07-04 20:15:47

How to make this regular expression find matches not one by one, but the whole block at once (On the service for checking regular expressions, this is true, but not in php)?

Hello! Here is this line:
preg_replace('/[ \t]{1,}/m', 'z', $string);
If you take a regular expression and check it on some online service for checking regular expressions, then it finds the entire block at once. And in php, each whitespace character is replaced by the letter z one by one. The result is a lot of letters z. And there should have been one. How do I get a single letter z instead of all whitespace characters together?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
ThunderCat, 2018-07-04
@sorry_i_noob

So?
preg_replace('/[\s]*/m', 'z', $string);

B
bioGavs, 2018-07-04
@bioGavs

Like this ? but in general, here is a service in which you can test under php and other languages

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question