Answer the question
In order to leave comments, you need to log in
How to get the value in a string in square brackets using a regular expression?
There is a line like "some text [any number]"
How to get the value in square brackets in php, along with the square brackets themselves?
That is, from the string "some text [any number]" you need to get "[any number]".
To be completely accurate, I need to get a string without everything that is in square brackets, leaving only "some text"
in php, for this you can use preg_replace($pattern, "", "text[3]"); // text
Here's what to specify in $pattern?
Answer the question
In order to leave comments, you need to log in
https://regex101.com/r/iN7rY2/2
$str = 'некий текст[36465464]';
echo $str, PHP_EOL;
echo preg_replace('/\[\d+\]/', '', $str);
ideone.com/OOAxcK
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question