Gumuliokas
Gumuliokas

Reputation: 73

PHP remove portion of a string by pattern

i have bunch of strings, where i need cut out one portion:

1. Adaptation of a one-step worst-case optimal univariate algorithm of bi-objective Lipschitz optimization to multidimensional problems, vol. 21 [looked: 2014 m. september 15 d.], p. 89-98.
2. On benchmarking stochastic global optimization algorithms, 2014 [looked 2014 m. spetember 17 d.], p. 9-12.
3. Quadratic programming with complementarity constraints for multidimensional scaling with city-block distances, Vol. 2, no. 4 [looked 2014 m. december 05 d.], p. 248-259. 

and many others. I need remove [looked YYYY m. month dd d.] portion. Which begins with "[looked" and ends with "]". How can i achieve this?

i have tried preg_replace, but i cannot build up great working pattern.

Upvotes: 1

Views: 27

Answers (2)

Andrius
Andrius

Reputation: 5939

This works:

preg_replace("/\[looked(.+?)\]/","",$str)

Upvotes: 1

Avinash Raj
Avinash Raj

Reputation: 174696

You may try this,

preg_replace('~\[Looked\b[^\]]*\]~', '', $str);

Upvotes: 1

Related Questions