Answer the question
In order to leave comments, you need to log in
How to select a string up to certain characters?
For example, you need to select a string up to one of the following characters: ,;
.
In this case, the solution is simple: /^[^,;]+/
Actually, the question is: how to select a string up to a group of characters?
For example, before \s[a-z]
(space and any letter). Something like: /^[^,;ГРУППА]+/
UPD: you need to select a string, both up to individual characters, and up to some group of characters
Answer the question
In order to leave comments, you need to log in
Use capturing groups: https://regex101.com/r/qN5qP8/3
UPD : Updated, regexp now with alternative groups
The desired sequence must be grouped using brackets. The (?=) construct means that whatever is in the brackets will not be part of the match.
You can do this:
But in this case, the part of the string you are interested in will be in the first group, and the full match will be along with a space and a letter at the end.
I recommend two services in which it is convenient to check regular expressions:
* pcre.ru ( example for your case)
* regex101.com
Positive lookahead .
$re = '(.+?)(?=[,;]+)'; // второе условие модифицируйте и забирайте данные
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question