L
L
LittleFatNinja2015-08-21 16:24:13
PHP
LittleFatNinja, 2015-08-21 16:24:13

How to optimally find the first occurrence of a substring before any character that is not a letter?

Let's say there is a string,
$str = 'Синее море'
but it can also be
$str = 'Синее. Море'
How is it best to find "Blue"? That is, find the first occurrence of a substring up to a non-letter character?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2015-08-21
@LittleFatNinja

That is, find the first occurrence of a substring up to a non-letter character?

The problem in this formulation can be reformulated:
$str = 'Синее. Море';
if (preg_match('/^\w+/u', $str, $match)) {
    echo $match[0];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question