1

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.

2 Answers 2

1

You may try this,

preg_replace('~\[Looked\b[^\]]*\]~', '', $str);
Sign up to request clarification or add additional context in comments.

1 Comment

add \s* before the first \[ , if you want to remove also the leading spaces.
1

This works:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.