M
M
Morfeey2017-10-13 13:40:47
Regular Expressions
Morfeey, 2017-10-13 13:40:47

How to write a regular expression to clean strings from square brackets at the beginning and end?

There is a line: [-]
We need a regular expression for cleaning with (preg_replace) from "[]", the most important thing is that "[" is cleaned from the beginning of the line, and "]" from the end.
I tried to do this: "/^[$]/" and "/^\[$\]/", but there is no result.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Gleb Starkov, 2017-10-13
@colonel

preg_replace('/^\[(.+)\]$/', '$1', $someString);

A
Alexander, 2017-10-13
@zkelo

Another option

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question