there is a string like

'[text1] text2 - text3' 

or

 'text2 - text3' 

that is, sometimes there is [text1] in square brackets, and sometimes not, and always before text2 there is -

you need php to cut off and leave only 'text2'

example:

 [Гайд] For Honor - Завоеватель - непоколебимый защитник Overwatch - Глава Xbox прокомментировал ситуацию с использованием мыши и клавиатуры World of Warcraft - В игре началась “Любовная лихорадка” 

it should work

 For Honor Overwatch World of Warcraft 

Closed due to the fact that the essence of the question is not clear by the participants user194374, ermak0ff , rjhdby , Vadizar , user207618 Mar 5 '17 at 15:45 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Give an example of data. What could be in test\d ? - user207618
  • 3
    What regular expression did you get? - Wiktor Stribiżew
  • one
    In text2 can be `-`? - user207618
  • one
    Show what you have already written. And we will correct it. For convenience, you can use one of the online designers of regulary varazhy. Well ... Or do everything through implode \ explode with arrays and different conditions. - n.osennij
  • one
    And yet, the author, please mark the answers to the questions as accepted if they helped you (there is a tick to the left of the answer). Try to add this question - add the regulars, which you got, even if it is completely non-working, then the disadvantages to the question will gradually turn into pluses. - Mae

1 answer 1

Just a regular expression is suitable for this:

 (?:\[.+?\])?\ ?(.+?)\ \-\ .+ 

Working example: https://regex101.com/r/p6oW3g/3