V
V
Vladislav2020-04-23 09:19:32
PHP
Vladislav, 2020-04-23 09:19:32

Regulator not working properly?

Wrote such a regular expression to separate the numbers from the text.
https://regex101.com/r/yBWKBd/1
on regex tester everything works correctly, it is divided into two groups, in one text in the other numbers.

in php sandbox code( sandbox.onlinephpfunctions.com ):

<?php
$re = '/([a-zA-Zа-яА-Я]+)([0-9]+)/';
$str = 'Сообщения21';

preg_match($re, $str, $matches);

var_dump($matches);

Gives a response like this:
array(3) {
  [0]=>
  string(10) "ения21"
  [1]=>
  string(8) "ения"
  [2]=>
  string(2) "21"
}


And it should be like this: [0 => 'Messages', 1 => '21' ]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Pokrovsky, 2020-04-23
@cr1gger

and so?
'/(\D+)(\d+)/'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question