Answer the question
In order to leave comments, you need to log in
How to make regex work in php?
Hello. There is such a regular expression "(\s|^)(\[.*?\]|.*?)(?=(\s|$))" in js when I run it like this, the line is split into an array
'Купить !автомобиль [недорого москва] [новый или !бу]'.match(/(\s|^)(\[.*?\]|.*?)(?=(\s|$))/g).map(x=>x.trim())
but in php it doesn't work like that, it returns 5 empty array elements.preg_split('/(\s|^)(\[.*?\]|.*?)(?=(\s|$))/', 'Купить !автомобиль [недорого москва] [новый или !бу]')
Why is this and how can it be fixed?
Answer the question
In order to leave comments, you need to log in
preg_match_all
preg_match_all('/(\s|^)(\[.*?\]|.*?)(?=(\s|$))/', 'Купить !автомобиль [недорого москва] [новый или !бу]', $m);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question