A
A
Andrey Eskov2018-02-01 10:23:29
PHP
Andrey Eskov, 2018-02-01 10:23:29

What should the regular expression look like in my case?

What should the regular expression look like?
There is a line

10 000 руб
12 000 руб

preg_replace('/[^\d]/', '', $string);
The essence of the question is that I need to get the number only from the first line, the second is simply ignored. But I can’t say for sure whether there is a line break there, since I get the line at the time of parsing.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nick Sdk, 2018-02-01
@taurus2790

preg_replace('/^([\s\d]+).*/is', '$1', $str);
then you can remove the spaces
preg_replace('/\s+/', '', $str);

D
Dmitry Kim, 2018-02-01
@kimono

preg_replace('/^(\d+)\s(\d+).*/s', '$1$2', $str);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question