Regex replace [something] KeepThisPart

I need some regex to remove [both ]the beginning of the line and everything in the middle like this:

[text]KeepThisshould be KeepThis.

It seems I can’t figure out how to do this (not so long ago I used regex :))

+3
source share
1 answer
$result = preg_replace( '/^\[.*?\]/', '', $string );

The regular expression finds any pair of brackets and their contents from the beginning of the line and replaces it with an empty line.

+2
source

Source: https://habr.com/ru/post/1792637/


All Articles