[SOLVED] Get German title and year of movie with regex


This Content is from Stack Overflow. Question asked by Daniel Schmitt

I would like to remove everything from string except title and year of a movie

I would like to keep everything that’s not in a bracket:



This is what I tried:



Does anyone has a clue how to do it? Need some examples maybe


You can get close to what you need using


See the regex demo. Details:

  • \[ – a [ char
  • [^\]\[]* – zero or more chars other than [ and ]
  • ] – a ] char
  • | – or
  • \W* – zero or more non-word chars
  • \b – a word boundary
  • (?:\d{4}|German|DE) – four digits or German or DE
  • \b – a word boundary
  • (?!.*\[[^\]\[]*]) – immediately to the right of the current location, there should not be
    • .* – any zero or more chars other than line break chars as many as possible
    • \[[^\]\[]*][, zero or more chars other than [ and ] and then a ]
  • .* – the rest of the line.

This Question was asked in StackOverflow by Daniel Schmitt and Answered by Wiktor Stribi┼╝ew It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?