Answer the question
In order to leave comments, you need to log in
How to escape regex characters in multibyte strings?
I have a regular expression that contains external data, if a string containing service characters of a regular expression comes from external data, then this will show the whole pattern, I tried to find a built-in function for escaping characters in multibyte strings - I did not find it. How to escape regex characters?
Example:
function f(string $data)
{
//Здесь сначала нужно экранировать символы в строке, но как это сделать?
$data = screening($data);
//Затем передать в паттерн регулярного выражения
$pattern = "^{$data}+|{$data}+$";
}
Answer the question
In order to leave comments, you need to log in
The \Q and \E sequences escape the service characters between them. \Q - start, \E end escaping: \d\Q(some)\E\d - parentheses here are just parentheses
Apparently, $data = "\Q$data\E" should work (or "\\Q$ data\\E")
PS. just noticed that the question was asked 10 days ago... I guess you already found the answer...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question